Compare commits

...

750 Commits

Author SHA1 Message Date
Liam Newman
eff48dfe67 [maven-release-plugin] prepare release github-api-1.99 2019-11-04 10:08:55 -08:00
Liam Newman
0c38bdc068 Merge pull request #590 from github-api/dependabot/maven/org.apache.maven.plugins-maven-source-plugin-3.2.0
Bump maven-source-plugin from 3.1.0 to 3.2.0
2019-11-04 09:35:00 -08:00
Liam Newman
b8e1736696 [maven-release-plugin] prepare for next development iteration 2019-11-04 09:16:45 -08:00
Liam Newman
c2f36444d0 [maven-release-plugin] prepare release github-api-1.98 2019-11-04 09:16:39 -08:00
Liam Newman
5dc74f5b4d [maven-release-plugin] prepare for next development iteration 2019-11-04 08:30:58 -08:00
Liam Newman
9694dfe4cc [maven-release-plugin] prepare release github-api-1.97 2019-11-04 08:30:51 -08:00
Liam Newman
734125ea14 [maven-release-plugin] prepare for next development iteration 2019-11-04 08:07:30 -08:00
Liam Newman
438f5d1b87 [maven-release-plugin] prepare release github-api-1.96 2019-11-04 08:07:19 -08:00
dependabot-preview[bot]
fadd6d7978 Bump maven-source-plugin from 3.1.0 to 3.2.0
Bumps [maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.1.0 to 3.2.0.
- [Release notes](https://github.com/apache/maven-source-plugin/releases)
- [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.1.0...maven-source-plugin-3.2.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-04 13:12:37 +00:00
Liam Newman
5026262273 Merge pull request #578 from martinvanzijl/issue_457_create_team_with_repo_access_fix
GHOrganization.createTeam now adds team to specified repositories
2019-11-01 10:50:53 -07:00
Liam Newman
5b53fba020 Merge pull request #581 from martinvanzijl/issue_546_list_repository_topics
Add method to list repository topics
2019-11-01 09:33:10 -07:00
Liam Newman
3892e6e16f Merge branch 'master' into issue_457_create_team_with_repo_access_fix 2019-11-01 09:30:50 -07:00
Liam Newman
33467de763 Formatting and snapshot cleanup 2019-11-01 09:30:33 -07:00
Martin van Zijl
f3528d97c2 Move team cleanup to @Before method as per GitHub review.
Removed constant for TEAM_NAME as it is now only used once in
the method.
2019-11-01 14:48:20 +13:00
Liam Newman
6fb3b01bf0 Fix gpg signing 2019-10-31 18:10:04 -07:00
Martin van Zijl
e3c9cec440 Fixed typo in comment: listTopics() not getTopics(). 2019-11-01 13:48:20 +13:00
Liam Newman
0e011425fb Merge pull request #586 from PauloMigAlmeida/master
[Documentation] :: Add GitHub App Developer Guide
2019-10-31 17:47:23 -07:00
Liam Newman
ba658f7fea Merge branch 'master' into master 2019-10-31 17:47:12 -07:00
Liam Newman
0e6087143b Merge pull request #587 from bitwiseman/site-build
Fix site errors
2019-10-31 17:46:45 -07:00
Liam Newman
5f967e6307 Fix javadoc on java 11 2019-10-31 17:41:05 -07:00
Martin van Zijl
2eb8ce632c Merge branch 'master' into issue_546_list_repository_topics 2019-11-01 13:35:57 +13:00
Liam Newman
f25dbd15d9 Stabilize time check 2019-10-31 16:10:34 -07:00
PauloMigAlmeida
cc5ea77170 Merge branch 'master' of https://github.com/kohsuke/github-api 2019-11-01 12:02:34 +13:00
PauloMigAlmeida
e323644af2 Correcting typos as pointed out during the code review
Signed-off-by: PauloMigAlmeida <paulo.miguel.almeida.rodenas@gmail.com>
2019-11-01 11:58:16 +13:00
Liam Newman
61f3a3219f Fix tt incompatible tags 2019-10-31 15:41:09 -07:00
Liam Newman
4dcf5dbc13 More pom fixes 2019-10-31 14:24:29 -07:00
Liam Newman
8faecba0a2 Fix site errors 2019-10-31 13:33:14 -07:00
Liam Newman
739551cbe3 Remove old index 2019-10-31 13:01:58 -07:00
PauloMigAlmeida
24a2e42881 [Documentation] :: Add GitHub Developer Guide
Signed-off-by: PauloMigAlmeida <paulo.miguel.almeida.rodenas@gmail.com>
2019-11-01 02:02:07 +13:00
Liam Newman
6921754c99 Merge pull request #585 from github-api/add-code-of-conduct-1
Create CODE_OF_CONDUCT.md
2019-10-30 17:22:09 -07:00
Liam Newman
d8827a0b44 Create CODE_OF_CONDUCT.md 2019-10-30 17:21:56 -07:00
Liam Newman
a48091988f Update release-drafter.yml 2019-10-30 17:04:40 -07:00
Liam Newman
9bd9c9cf1f Create release-drafter.yml 2019-10-30 16:29:26 -07:00
Liam Newman
695692285b Merge pull request #579 from martinvanzijl/issue_512_methods_to_update_milestones
Add methods to update and delete milestones.
2019-10-30 15:47:50 -07:00
Liam Newman
03edacf7b6 Enable test for Milestone due date update 2019-10-30 15:05:35 -07:00
Liam Newman
4802c97e89 Fix GitHub.printDate()
GitHub.printDate() was not setting GMT timezone resulting in completely bogus output.
2019-10-30 14:57:56 -07:00
Liam Newman
9fc24d1981 Merge branch 'master' into issue_512_methods_to_update_milestones 2019-10-30 12:57:18 -07:00
Liam Newman
d4ddf453b0 Merge pull request #580 from martinvanzijl/issue_529_fix_get_deployment_by_id
Fix for getting deployment by id
2019-10-30 12:55:58 -07:00
Liam Newman
c0117f07cf Merge pull request #583 from PauloMigAlmeida/master
Convenience method to auth with app installation token && documentation examples
2019-10-30 12:54:28 -07:00
Paulo Miguel Almeida
8a88c14b13 Add convenience method to authenticate with app installation tokens;
Convert existing markdown doc to APT due to formatting features;
Replace occurrences of kohsuke user to github-api org where applicable;
Fix repositoryIds method on GHAppCreateTokenBuilder;

Signed-off-by: PauloMigAlmeida <paulo.miguel.almeida.rodenas@gmail.com>
2019-10-30 22:18:12 +13:00
Martin van Zijl
a5b6302a69 Add method to list repository topics.
For #546.

The method to update repository topics does not work yet. It may
not have been implemented in the underlying API.
2019-10-30 15:05:09 +13:00
Martin van Zijl
9f29d4619d Fix for getting deployment by id.
Fixes #529.
2019-10-30 13:13:06 +13:00
Martin van Zijl
f4b9dd7d7b Add methods to update and delete milestones.
Fixes #512.
2019-10-30 12:20:06 +13:00
Martin van Zijl
c0a4152b00 GHOrganization.createTeam now adds team to specified repositories.
Fixes #457.
2019-10-29 17:49:41 +13:00
Liam Newman
efb87c5a9e Adjust Jacoco targets to further point to untouched classes. 2019-10-25 19:09:26 -07:00
Liam Newman
061e8bb662 Stop printing to System 2019-10-25 18:33:54 -07:00
Liam Newman
a4f42b2948 Add more tests from AppTest 2019-10-25 18:31:40 -07:00
Liam Newman
cb2fcd3a9e Enable Jacoco on at has-it-been-touched reporting 2019-10-25 18:19:13 -07:00
Liam Newman
1d004a35a0 Merge pull request #510 from awittha/get-user-orgs
Added getUserPublicOrganizations method
2019-10-24 18:32:09 -07:00
Austin Witt
c763c02018 [added] unit tests for getUserPublicOrganizations(...) 2019-10-24 11:03:37 -05:00
Austin Witt
eb36cb4436 Merge remote-tracking branch 'upstream/master' into get-user-orgs 2019-10-23 14:39:54 -05:00
Liam Newman
72d4b9bf62 Merge pull request #525 from vbehar/draft-pr
Add support for draft pull requests
2019-10-21 16:01:02 -07:00
Liam Newman
81ea138f41 Test and fixes for draft pull request 2019-10-21 15:38:04 -07:00
Liam Newman
1bbc66ad62 Merge remote-tracking branch 'github-api/master' into draft-pr 2019-10-21 14:34:40 -07:00
Liam Newman
e7348df372 Merge pull request #575 from romani/patch-1
bump jackson-databind to 2.10.0 to avoid security alert
2019-10-21 12:56:12 -07:00
Roman Ivanov
550e060647 bump jackson-databind to 2.10.0 to avoid security alert 2019-10-20 06:37:28 -07:00
Liam Newman
2970a58e95 Merge branch 'master' into draft-pr 2019-10-18 13:00:39 -07:00
Liam Newman
e0efa04fd4 Merge pull request #574 from github-api/dependabot/maven/com.github.tomakehurst-wiremock-jre8-standalone-2.25.1
Bump wiremock-jre8-standalone from 2.25.0 to 2.25.1
2019-10-18 13:00:14 -07:00
dependabot-preview[bot]
4d24088982 Bump wiremock-jre8-standalone from 2.25.0 to 2.25.1
Bumps [wiremock-jre8-standalone](https://github.com/tomakehurst/wiremock) from 2.25.0 to 2.25.1.
- [Release notes](https://github.com/tomakehurst/wiremock/releases)
- [Commits](https://github.com/tomakehurst/wiremock/compare/2.25.0...2.25.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-18 19:58:47 +00:00
Liam Newman
baba9f5de6 Merge pull request #573 from github-api/dependabot/maven/hamcrest.version-2.2
Bump hamcrest.version from 2.1 to 2.2
2019-10-18 12:57:35 -07:00
dependabot-preview[bot]
c35cd63d0e Bump hamcrest.version from 2.1 to 2.2
Bumps `hamcrest.version` from 2.1 to 2.2.

Updates `hamcrest` from 2.1 to 2.2
- [Release notes](https://github.com/hamcrest/JavaHamcrest/releases)
- [Changelog](https://github.com/hamcrest/JavaHamcrest/blob/master/CHANGES.md)
- [Commits](https://github.com/hamcrest/JavaHamcrest/compare/v2.1...v2.2)

Updates `hamcrest-core` from 2.1 to 2.2
- [Release notes](https://github.com/hamcrest/JavaHamcrest/releases)
- [Changelog](https://github.com/hamcrest/JavaHamcrest/blob/master/CHANGES.md)
- [Commits](https://github.com/hamcrest/JavaHamcrest/compare/v2.1...v2.2)

Updates `hamcrest-library` from 2.1 to 2.2
- [Release notes](https://github.com/hamcrest/JavaHamcrest/releases)
- [Changelog](https://github.com/hamcrest/JavaHamcrest/blob/master/CHANGES.md)
- [Commits](https://github.com/hamcrest/JavaHamcrest/compare/v2.1...v2.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-16 23:05:29 +00:00
Liam Newman
80fa389ce3 Fix GHContent.read()
Fixes #487
2019-10-11 15:21:57 -07:00
Liam Newman
8ec861c9fe Merge pull request #563 from bitwiseman/paged_iterable_closure
Simplify creation of PagedIterables from requests
2019-10-11 13:20:17 -07:00
Liam Newman
837400fb5e Merge pull request #572 from sullis/java-matrix-jdk13
GitHub workflow: add JDK 13 to build matrix
2019-10-11 13:18:00 -07:00
Liam Newman
ec4525b8ff Merge branch 'master' into java-matrix-jdk13 2019-10-11 13:13:09 -07:00
Liam Newman
281c927971 Update GHIssueEvent PagedIterable 2019-10-11 13:11:08 -07:00
Liam Newman
9dd44c13e4 Update for AuthorizationList 2019-10-11 13:05:13 -07:00
Liam Newman
f28edbcf8f Simplify creation of PagedIterables from requests 2019-10-11 13:05:13 -07:00
Liam Newman
29e147f992 wrupUp() package private 2019-10-11 13:02:42 -07:00
Sean C. Sullivan
830f4231e1 GitHub workflow: add JDK 13 to build matrix 2019-10-11 12:08:03 -07:00
Liam Newman
7d65e31055 Merge pull request #484 from martinvanzijl/issue_466_edit_gists
Add support for editing Gists
2019-10-11 11:46:56 -07:00
Liam Newman
dec7a91b5b Merge pull request #479 from martinvanzijl/issue_376_issue_events
Add issue events API
2019-10-11 11:44:03 -07:00
Liam Newman
1ba630c221 Minor Gist updater improvement 2019-10-11 11:21:11 -07:00
Martin van Zijl
7d3387fb96 Updated unit tests. 2019-10-11 16:37:08 +13:00
Liam Newman
a0c0de28d7 Move a few more tests to use temp repo 2019-10-09 13:41:00 -07:00
Liam Newman
dc31d52f83 Add facility to create and auto-cleanup temp repos 2019-10-09 13:00:21 -07:00
Martin van Zijl
620c822dac Updates per review on GitHub:
- Created class GHGistUpdater to do the updating.
- Added unit tests.
2019-10-10 07:08:05 +13:00
Liam Newman
5990f5ae22 Merge pull request #567 from jberglund-BSFT/master
Add merge options to GHRepository
2019-10-09 11:02:54 -07:00
Martin van Zijl
37329a50d4 Merge branch 'master' into issue_466_edit_gists 2019-10-10 05:43:10 +13:00
Martin van Zijl
550597f72e Make unit test output neater. 2019-10-09 15:11:02 +13:00
Martin van Zijl
2aa4022e2c Updated per review.
- Created separate class for GHIssueEvent instead of nested classes.
- Renamed test class accordingly.

Other fixes:

- Changed id type to long.
- Updated test cases.
- Added toString() method.
2019-10-09 14:59:08 +13:00
Martin van Zijl
b40741b14d Merge branch 'issue_376_issue_events' of https://github.com/martinvanzijl/github-api into issue_376_issue_events 2019-10-09 14:03:27 +13:00
Joey Berglund
3c739d889e Merge branch 'master' into master 2019-10-08 15:04:55 -05:00
Liam Newman
24a92a133e Merge branch 'master' into issue_376_issue_events 2019-10-08 11:04:22 -07:00
Liam Newman
ce97eb5b40 Merge pull request #482 from martinvanzijl/issue_467_add_user_to_org
Add method to invite user to organization
2019-10-08 11:04:01 -07:00
Liam Newman
7a4e3c480e Merge branch 'master' into issue_467_add_user_to_org 2019-10-08 10:59:27 -07:00
Liam Newman
eefa710839 Merge branch 'master' into issue_466_edit_gists 2019-10-08 10:59:09 -07:00
Liam Newman
4c3e1afcca Merge branch 'master' into get-user-orgs 2019-10-08 10:57:48 -07:00
Liam Newman
c1a77ada5d Merge branch 'master' into draft-pr 2019-10-08 10:55:51 -07:00
Liam Newman
5671e5ed67 Merge branch 'master' into master 2019-10-08 10:54:23 -07:00
Liam Newman
2fdc5a8541 Merge pull request #562 from sullis/github-workflow-java-matrix
GitHub workflow: enable Java matrix [ '1.8.0', '11.0.x' ]
2019-10-08 10:51:37 -07:00
Liam Newman
297dbae247 Merge branch 'master' into github-workflow-java-matrix 2019-10-08 10:47:19 -07:00
Liam Newman
0910cdf3a4 Add test for bridge method 2019-10-08 10:37:51 -07:00
jberglund
6877fb5c74 add unit test 2019-10-08 11:20:34 -05:00
Liam Newman
2d65daa8c9 Merge branch 'master' into master 2019-10-08 08:21:54 -07:00
Sean C. Sullivan
dab4cb6186 cleanup pom.xml 2019-10-07 22:46:40 -07:00
Sean C. Sullivan
40773a2b49 GitHub workflow: enable Java matrix [ '1.8.0', '11.0.x' ] 2019-10-07 22:37:58 -07:00
Liam Newman
7e0d61a6fc Merge pull request #481 from martinvanzijl/issue_459_list_authorizations
Added method to list authorizations
2019-10-07 19:04:00 -07:00
Liam Newman
7f9620d75f Delete Foo.java 2019-10-07 18:46:02 -07:00
Martin van Zijl
3559aef1a1 Fixes per review.
- Added missing brace at end of listMyAuthorizations().
- Added unit test for listMyAuthorizations().
2019-10-08 13:21:48 +13:00
Martin van Zijl
94ceb5eaaf Merge branch 'master' into issue_459_list_authorizations 2019-10-08 12:42:18 +13:00
Martin van Zijl
778ca76d22 Merge branch 'issue_376_issue_events' of https://github.com/martinvanzijl/github-api into issue_376_issue_events 2019-10-08 12:34:44 +13:00
Martin van Zijl
b1c0e41c5c Merge branch 'master' into issue_376_issue_events 2019-10-08 12:31:30 +13:00
Liam Newman
f826edd097 Merge pull request #564 from github-api/dependabot/maven/com.squareup.okio-okio-2.4.1
Bump okio from 2.4.0 to 2.4.1
2019-10-07 14:09:42 -07:00
Liam Newman
edc7c4a4b8 Merge pull request #565 from github-api/dependabot/maven/com.google.code.gson-gson-2.8.6
Bump gson from 2.8.5 to 2.8.6
2019-10-07 14:09:11 -07:00
Liam Newman
dafdc66d25 Merge pull request #568 from bitwiseman/more-tests
More tests
2019-10-07 14:08:45 -07:00
Liam Newman
0d135f14bb Add more CI tests 2019-10-07 14:01:32 -07:00
Liam Newman
568c08d0e9 Separate connection sensitive tests 2019-10-07 13:09:27 -07:00
Liam Newman
87410e295e Add more tests to ci 2019-10-07 13:04:13 -07:00
Joey Berglund
b163e68950 Merge branch 'master' into master 2019-10-07 08:41:56 -05:00
Joey Berglund
88b006e957 Update GHRepository.java 2019-10-07 08:39:38 -05:00
dependabot-preview[bot]
477f2f2814 Bump gson from 2.8.5 to 2.8.6
Bumps [gson](https://github.com/google/gson) from 2.8.5 to 2.8.6.
- [Release notes](https://github.com/google/gson/releases)
- [Changelog](https://github.com/google/gson/blob/master/CHANGELOG.md)
- [Commits](https://github.com/google/gson/compare/gson-parent-2.8.5...gson-parent-2.8.6)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-07 08:09:06 +00:00
dependabot-preview[bot]
933d99c23b Bump okio from 2.4.0 to 2.4.1
Bumps [okio](https://github.com/square/okio) from 2.4.0 to 2.4.1.
- [Release notes](https://github.com/square/okio/releases)
- [Changelog](https://github.com/square/okio/blob/master/CHANGELOG.md)
- [Commits](https://github.com/square/okio/compare/parent-2.4.0...2.4.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-07 08:08:48 +00:00
Martin van Zijl
d3a0c5ded1 Added unit test for adding user to organization. 2019-10-07 15:34:13 +13:00
Martin van Zijl
1e173ddc24 Merge branch 'master' of https://github.com/kohsuke/github-api into issue_467_add_user_to_org 2019-10-07 13:56:08 +13:00
Liam Newman
ca404cb33b Merge branch 'master' into issue_466_edit_gists 2019-10-05 19:40:56 -07:00
Liam Newman
f0dc7d5b02 Merge pull request #532 from farmdawgnation/team-pr-review-requests
Add support for team pr review requests
2019-10-05 19:39:55 -07:00
Liam Newman
933702376f Update Tests to check for lazy loading and refresh 2019-10-05 14:35:13 -07:00
Liam Newman
e08896775b Add Refreshable interfrace and use it in GHTeam and GHPullRequest 2019-10-05 14:17:17 -07:00
Matt Farmer
d610e46f8e Add a test for team review requests 2019-10-05 09:19:28 -04:00
Matt Farmer
7d1989f5a2 Materialize requested_teams from the teams API
We don't get the full object when we retrieve a PR, so when we see
requested teams we need to materialize them from the API
2019-10-05 09:13:13 -04:00
Matt Farmer
5c1e371427 Rebuild wiremock for test review requests 2019-10-05 08:35:12 -04:00
Matt Farmer
dbd9d51747 Merge remote-tracking branch 'upstream/master' into team-pr-review-requests 2019-10-05 08:29:27 -04:00
Liam Newman
fdf5d3f72d Merge pull request #475 from immanuelqrw/label-description
Adding Label description property
2019-10-04 22:28:11 -07:00
Liam Newman
2719867a86 Fix up Label Description and tests 2019-10-04 22:23:53 -07:00
Liam Newman
0240412ad2 Merge remote-tracking branch 'github-api/master' into label-description 2019-10-04 21:44:06 -07:00
Liam Newman
7c065c1205 Merge pull request #477 from martinvanzijl/issue_330_statistics
Add statistics API.
2019-10-04 21:38:08 -07:00
Liam Newman
f9aa1ad1f2 Fix JSON API FB warning 2019-10-04 21:34:55 -07:00
Liam Newman
5feffdf544 Minor fixups after merge from master
Rerecorded WireMock files with newer framework
2019-10-04 21:29:08 -07:00
Liam Newman
4e56b8bb78 Merge branch 'master' into issue_330_statistics 2019-10-04 21:12:35 -07:00
Liam Newman
845017313c Merge pull request #545 from gskjold/issue_425_projects_columns_cards
Support for projects
2019-10-04 21:10:51 -07:00
Liam Newman
dc2830d94f Enable Content test 2019-10-04 21:06:15 -07:00
Liam Newman
552edf8698 Switch to WireMockMultiServerRule as base 2019-10-04 21:06:00 -07:00
Liam Newman
41c51646fe Rename GitHubApiWireMockRule to GitHubWireMockRule 2019-10-04 21:02:44 -07:00
Joey Berglund
a42024bdbc Update GHRepository.java 2019-10-04 16:28:28 -05:00
Liam Newman
20cfb26a7f Disable Licence content test
Need to mock raw.githubusercontent.com to make this work
2019-10-04 11:09:05 -07:00
Liam Newman
3972d11827 WireMock License Test 2019-10-04 10:30:22 -07:00
Liam Newman
5cc88a0075 WireMock Project Tests 2019-10-04 10:27:47 -07:00
Gunnar Skjold
fc08711111 Expanded GHProject with columns and cards. Also added tests for projects, columns and cards 2019-10-04 10:11:18 -07:00
Martin van Zijl
b20c2babec Added support for projects.
Fixes issue #425
2019-10-04 10:11:18 -07:00
Martin van Zijl
cb0facc6ef Updates per GH review.
- Marked getContributorStats(bool) as deprecated, preview
- Moved "stats/" string to getApiTailUrl()
2019-10-05 05:43:23 +13:00
Liam Newman
78abb2edcb Merge pull request #530 from bozaro/request-log
Add GitHub API requests logging
2019-10-04 09:15:09 -07:00
Liam Newman
7d350d9def Merge pull request #561 from github-api/dependabot/maven/org.eclipse.jgit-org.eclipse.jgit-5.5.1.201910021850-r
Bump org.eclipse.jgit from 5.5.0.201909110433-r to 5.5.1.201910021850-r
2019-10-04 08:15:48 -07:00
dependabot-preview[bot]
48d7daf2c4 Bump org.eclipse.jgit from 5.5.0.201909110433-r to 5.5.1.201910021850-r
Bumps org.eclipse.jgit from 5.5.0.201909110433-r to 5.5.1.201910021850-r.

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-04 08:22:03 +00:00
Liam Newman
2782059d88 Merge branch 'master' into request-log 2019-10-04 00:44:21 -07:00
Liam Newman
0ca10bc2ac Merge branch 'master' into issue_459_list_authorizations 2019-10-04 00:43:14 -07:00
Liam Newman
880abe2305 Merge branch 'master' into issue_467_add_user_to_org 2019-10-04 00:41:50 -07:00
Liam Newman
22f61d6225 Merge branch 'master' into issue_376_issue_events 2019-10-04 00:41:15 -07:00
Liam Newman
4fbaa425fb Merge branch 'master' into issue_466_edit_gists 2019-10-04 00:36:18 -07:00
Liam Newman
e81e228f03 Merge branch 'master' into issue_330_statistics 2019-10-04 00:01:36 -07:00
Liam Newman
1076f89954 Merge branch 'master' into label-description 2019-10-03 23:56:27 -07:00
Liam Newman
9c6f977202 Merge branch 'master' into get-user-orgs 2019-10-03 23:55:56 -07:00
Martin van Zijl
bd23ba6077 Added Wiremock test files. 2019-10-04 16:27:41 +13:00
Martin van Zijl
c7af56d0ed Changes per review on GitHub.
- Moved statistics methods from GHRepository to new class GHRepositoryStatistics
- Updated StatisticsTest to suit.
- For ContributorStats, put the "wait-till-ready" loop in the accessor method.
  I'm planning to do something similar for the rest.
2019-10-04 16:23:26 +13:00
Liam Newman
8da6db9fcc Merge pull request #522 from PauloMigAlmeida/master
Implement GitHub App API methods
2019-10-03 19:29:37 -07:00
Liam Newman
2fe7342fd7 Merge branch 'master' into master 2019-10-03 19:07:40 -07:00
Liam Newman
f6221144a8 Merge pull request #478 from martinvanzijl/issue_460_team_description_field
Added description field to GHTeam class.
2019-10-03 17:37:52 -07:00
Liam Newman
872d713e50 Fix one more case of connecting outside the proxy 2019-10-03 17:34:52 -07:00
Liam Newman
d5b04f572b Fixed list traversal for paged queries 2019-10-03 17:23:31 -07:00
PauloMigAlmeida
0f7a5f1c08 Merge from upstream;
Remove servlet exclusion due to previous JDK version;

Signed-off-by: PauloMigAlmeida <paulo.miguel.almeida.rodenas@gmail.com>
2019-10-04 11:59:58 +13:00
PauloMigAlmeida
a163c565a8 Merge branch 'master' of https://github.com/kohsuke/github-api
 Conflicts:
	src/main/java/org/kohsuke/github/GitHubBuilder.java
	src/test/java/org/kohsuke/github/GitHubTest.java
2019-10-04 11:56:38 +13:00
Liam Newman
413a316b15 Record snapshot for test 2019-10-03 14:51:46 -07:00
Liam Newman
65a92a49b5 Merge remote-tracking branch 'github-api/master' into issue_460_team_description_field 2019-10-03 14:44:04 -07:00
Sharath Babu
563507ca21 add setPrivate functionality on repos 2019-10-03 14:38:26 -07:00
Liam Newman
21b2d02f0a Enable GHOrganizationTest in CI 2019-10-03 14:20:18 -07:00
Liam Newman
19e1a00fd7 Rename mapping files to include index 2019-10-03 14:05:15 -07:00
Liam Newman
a02a6a22d0 Move to Gson for formatting json 2019-10-03 13:49:53 -07:00
Liam Newman
3488421f67 More WireMock tests 2019-10-03 12:34:32 -07:00
Liam Newman
34a961088c Initial attempt at auto-format of JSON 2019-10-03 09:06:31 -07:00
Liam Newman
b35509150a Enable part of AppTest in CI 2019-10-02 15:27:22 -07:00
Liam Newman
d096aa2065 Merge pull request #558 from github-api/dependabot/maven/com.squareup.okio-okio-2.4.0
Bump okio from 2.2.2 to 2.4.0
2019-10-02 09:12:45 -07:00
dependabot-preview[bot]
efd5bef102 Bump okio from 2.2.2 to 2.4.0
Bumps [okio](https://github.com/square/okio) from 2.2.2 to 2.4.0.
- [Release notes](https://github.com/square/okio/releases)
- [Changelog](https://github.com/square/okio/blob/master/CHANGELOG.md)
- [Commits](https://github.com/square/okio/compare/2.2.2...parent-2.4.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-02 15:57:35 +00:00
Liam Newman
b8c6e44ab6 Update okhttp3 (with Java 8)
This version of okhttp3 is the last to suppurt UrlFactory, but we've replaced it anyway in preparation for future updates.
2019-10-01 14:05:50 -07:00
Liam Newman
9a91cc43e2 Merge pull request #542 from bitwiseman/cache-fix
Improved OkHttpConnector caching behavior
2019-10-01 13:11:26 -07:00
Liam Newman
f4cbab52a7 Merge branch 'master' into cache-fix 2019-10-01 13:07:35 -07:00
Liam Newman
57b58cf203 Merge pull request #557 from github-api/dependabot/maven/org.mockito-mockito-core-3.1.0
Bump mockito-core from 3.0.0 to 3.1.0
2019-10-01 08:25:59 -07:00
dependabot-preview[bot]
9ba8ae08a1 Bump mockito-core from 3.0.0 to 3.1.0
Bumps [mockito-core](https://github.com/mockito/mockito) from 3.0.0 to 3.1.0.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](https://github.com/mockito/mockito/compare/v3.0.0...v3.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-01 12:54:01 +00:00
Liam Newman
dfe81f510e Add None and Zero Cache tests to CI 2019-09-30 16:23:08 -07:00
Liam Newman
f3a0b35442 Updated Tests to have non-cache tests run in CI 2019-09-30 11:05:11 -07:00
Liam Newman
64e3be3bc7 Merge branch 'master' into cache-fix 2019-09-30 09:13:52 -07:00
Liam Newman
4c82d1c56e Merge pull request #556 from github-api/dependabot/maven/com.github.tomakehurst-wiremock-jre8-standalone-2.25.0
Bump wiremock-jre8-standalone from 2.24.1 to 2.25.0
2019-09-30 09:13:06 -07:00
Liam Newman
d8451fc2f5 Implement new abstract methods from Admin 2019-09-30 09:00:55 -07:00
dependabot-preview[bot]
8078423252 Bump wiremock-jre8-standalone from 2.24.1 to 2.25.0
Bumps [wiremock-jre8-standalone](https://github.com/tomakehurst/wiremock) from 2.24.1 to 2.25.0.
- [Release notes](https://github.com/tomakehurst/wiremock/releases)
- [Commits](https://github.com/tomakehurst/wiremock/compare/2.24.1...2.25.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-09-30 08:40:16 +00:00
Liam Newman
68176b5695 Merge branch 'master' into draft-pr 2019-09-29 18:36:34 -07:00
Liam Newman
1bf7833959 Merge branch 'master' into request-log 2019-09-29 18:35:53 -07:00
Liam Newman
89770b922d Change listKeys to getKeys 2019-09-29 18:33:08 -07:00
Liam Newman
716947bbb1 Merge branch 'master' into draft-pr 2019-09-27 10:38:23 -07:00
Liam Newman
47e0d7786b Merge branch 'master' into cache-fix 2019-09-27 10:37:26 -07:00
Arngrimur Bjarnason
55f9c40bba Merge branch 'master' into getKeysForUser 2019-09-27 08:24:49 +02:00
Martin van Zijl
51afa30732 Added unit tests. 2019-09-26 14:32:30 +12:00
Liam Newman
23c07316ee Merge branch 'master' into label-description 2019-09-25 17:28:23 -07:00
Liam Newman
e740f52e5e Merge pull request #480 from martinvanzijl/issue_381_branch_url_escaping
Escape special characters in branch URLs
2019-09-25 17:15:50 -07:00
Liam Newman
a731109747 Add tests for URLEncoding 2019-09-25 17:11:46 -07:00
Martin van Zijl
a50a011eb3 Issue #381 - Escape branch URL.
This is using the "old" HTTP.UTF_8 Charset, since the new
StandardCharsets doesn't compile.
2019-09-25 16:59:58 -07:00
Liam Newman
e22c6d3a94 Merge branch 'master' into issue_330_statistics 2019-09-25 16:57:36 -07:00
Liam Newman
50fb9c1795 Merge pull request #473 from joaoe/issue-472-archive-repository
Implemented GitHub.doArchive
2019-09-25 16:55:12 -07:00
Liam Newman
22575c9a01 Add test for archive method 2019-09-25 16:48:54 -07:00
João Eiras
2934922cb5 Implemented GitHub.doArchive
doArchive() will mark a repository as archived.

Issue #472
2019-09-25 16:30:44 -07:00
Liam Newman
9042ff46c7 Clean up Previews 2019-09-25 15:47:07 -07:00
Liam Newman
a1a91539c2 Merge branch 'master' into getKeysForUser 2019-09-25 10:13:39 -07:00
Liam Newman
468f4f94a3 Merge pull request #554 from github-api/dependabot/maven/org.apache.maven.plugins-maven-surefire-plugin-2.22.2
Bump maven-surefire-plugin from 2.22.1 to 2.22.2
2019-09-25 10:10:02 -07:00
Liam Newman
3ebd35437e Merge pull request #552 from github-api/dependabot/maven/org.apache.commons-commons-lang3-3.9
Bump commons-lang3 from 3.7 to 3.9
2019-09-25 10:09:33 -07:00
dependabot-preview[bot]
a166bbadad Bump maven-surefire-plugin from 2.22.1 to 2.22.2
Bumps [maven-surefire-plugin](https://github.com/apache/maven-surefire) from 2.22.1 to 2.22.2.
- [Release notes](https://github.com/apache/maven-surefire/releases)
- [Commits](https://github.com/apache/maven-surefire/compare/surefire-2.22.1...surefire-2.22.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-09-25 17:08:56 +00:00
Liam Newman
7ff07a132a Merge branch 'master' into dependabot/maven/org.apache.commons-commons-lang3-3.9 2019-09-25 10:08:33 -07:00
Liam Newman
6f297bcbb8 Merge pull request #555 from github-api/dependabot/maven/commons-io-commons-io-2.6
Bump commons-io from 1.4 to 2.6
2019-09-25 10:07:45 -07:00
dependabot-preview[bot]
1c023e15af Bump commons-io from 1.4 to 2.6
Bumps commons-io from 1.4 to 2.6.

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-09-25 07:33:21 +00:00
dependabot-preview[bot]
37f96848a7 Bump commons-lang3 from 3.7 to 3.9
Bumps commons-lang3 from 3.7 to 3.9.

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-09-25 07:32:00 +00:00
Liam Newman
3d04765f51 Merge branch 'master' into issue_330_statistics 2019-09-24 18:19:35 -07:00
Liam Newman
e1152fa549 Merge branch 'master' into issue_466_edit_gists 2019-09-24 14:34:15 -07:00
Liam Newman
ab47896f17 Merge branch 'master' into cache-fix 2019-09-24 14:29:36 -07:00
Liam Newman
4f13565e51 Merge pull request #549 from github-api/dependabot/maven/com.infradna.tool-bridge-method-annotation-1.18
Bump bridge-method-annotation from 1.17 to 1.18
2019-09-24 14:29:03 -07:00
dependabot-preview[bot]
7ab93a59e2 Bump bridge-method-annotation from 1.17 to 1.18
Bumps [bridge-method-annotation](https://github.com/infradna/bridge-method-injector) from 1.17 to 1.18.
- [Release notes](https://github.com/infradna/bridge-method-injector/releases)
- [Commits](https://github.com/infradna/bridge-method-injector/compare/bridge-method-injector-parent-1.17...bridge-method-injector-parent-1.18)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-09-24 21:26:18 +00:00
Liam Newman
943c0d022b Merge pull request #551 from github-api/dependabot/maven/commons-codec-commons-codec-1.13
Bump commons-codec from 1.7 to 1.13
2019-09-24 14:24:58 -07:00
dependabot-preview[bot]
bea8922c39 Bump commons-codec from 1.7 to 1.13
Bumps [commons-codec](https://github.com/apache/commons-codec) from 1.7 to 1.13.
- [Release notes](https://github.com/apache/commons-codec/releases)
- [Changelog](https://github.com/apache/commons-codec/blob/master/RELEASE-NOTES.txt)
- [Commits](https://github.com/apache/commons-codec/compare/1.7...commons-codec-1.13)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-09-24 21:23:03 +00:00
Liam Newman
97c96a7ee1 Merge pull request #550 from github-api/dependabot/maven/com.github.spotbugs-spotbugs-maven-plugin-3.1.12.2
Bump spotbugs-maven-plugin from 3.1.11 to 3.1.12.2
2019-09-24 14:21:43 -07:00
dependabot-preview[bot]
3d831ba7e8 Bump spotbugs-maven-plugin from 3.1.11 to 3.1.12.2
Bumps [spotbugs-maven-plugin](https://github.com/spotbugs/spotbugs-maven-plugin) from 3.1.11 to 3.1.12.2.
- [Release notes](https://github.com/spotbugs/spotbugs-maven-plugin/releases)
- [Commits](https://github.com/spotbugs/spotbugs-maven-plugin/compare/spotbugs-maven-plugin-3.1.11...spotbugs-maven-plugin-3.1.12.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-09-24 21:19:00 +00:00
Liam Newman
df749a98cb Merge pull request #547 from github-api/dependabot/maven/org.eclipse.jgit-org.eclipse.jgit-5.5.0.201909110433-r
Bump org.eclipse.jgit from 4.9.0.201710071750-r to 5.5.0.201909110433-r
2019-09-24 14:17:31 -07:00
dependabot-preview[bot]
22bbc9c621 Bump org.eclipse.jgit from 4.9.0.201710071750-r to 5.5.0.201909110433-r
Bumps org.eclipse.jgit from 4.9.0.201710071750-r to 5.5.0.201909110433-r.

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-09-24 19:46:06 +00:00
Liam Newman
30def4e515 Update jackson-databind to 2.9.10 2019-09-24 12:43:43 -07:00
Matt Farmer
cf8be37310 Correct test run + add sample data 2019-09-21 10:29:48 -04:00
Matt Farmer
12409df446 Merge remote-tracking branch 'upstream/master' into team-pr-review-requests 2019-09-21 09:56:12 -04:00
Martin van Zijl
3452a08de3 Added more detail to unit tests.
Added another accessor method.
2019-09-20 16:27:32 +12:00
Liam Newman
425ea0579e Merge branch 'master' into label-description 2019-09-17 13:33:50 -07:00
Arngrimur Bjarnason
22afb769af Adding wiremocks 2019-09-17 14:56:43 +02:00
Arngrimur Bjarnason
884eae269e Adding possiblity to get ssh keys 2019-09-17 14:39:46 +02:00
PauloMigAlmeida
59a973970e Remove duplicated wiremock dependency
Signed-off-by: PauloMigAlmeida <paulo.miguel.almeida.rodenas@gmail.com>
2019-09-15 10:57:22 +12:00
PauloMigAlmeida
225383464a Merge remote-tracking branch 'origin/master' 2019-09-15 10:52:53 +12:00
PauloMigAlmeida
3d82731325 Update tests using the new wiremock structure as per requested
Signed-off-by: PauloMigAlmeida <paulo.miguel.almeida.rodenas@gmail.com>
2019-09-15 10:52:22 +12:00
PauloMigAlmeida
dacdf08309 Merge branch 'master' of https://github.com/kohsuke/github-api 2019-09-14 17:00:24 +12:00
Martin van Zijl
ad281adc97 Unit tests and fixes.
Fixed issue with getCodeFrequency() where it would occasionally throw
an exception when the statistics were still being generated.

Added comment about throwing an exception as a possibility when
202 is returned.
2019-09-14 10:39:59 +12:00
Liam Newman
80741c7773 Use CacheControl and only check for cache in constructor 2019-09-12 13:57:28 -07:00
Liam Newman
532f7a4b17 Merge branch 'master' into cache-fix 2019-09-11 22:48:26 -07:00
Liam Newman
5e87d582e4 Add tests showing cache performance 2019-09-11 22:05:02 -07:00
Liam Newman
b9bf47aaca Merge pull request #543 from jsoref/grammar
Grammar
2019-09-11 20:48:28 -07:00
Josh Soref
0dba882817 spelling: create a 2019-09-11 19:28:32 -04:00
Josh Soref
c419883814 spelling: single 2019-09-11 19:28:24 -04:00
Josh Soref
6f0ccbf2b5 grammar: agreement: returns...organizations 2019-09-11 19:28:14 -04:00
Josh Soref
54332c0bd1 this api is no longer a preview... 2019-09-11 19:27:40 -04:00
Josh Soref
5f80674e89 finish thought... 2019-09-11 19:27:04 -04:00
Josh Soref
c4d0d8ff06 grammar: operations-require 2019-09-11 19:26:47 -04:00
Josh Soref
8ac1b7082a brand: GitHub Enterprise 2019-09-11 19:26:14 -04:00
Josh Soref
f146ae8be4 spelling: user 2019-09-11 19:25:55 -04:00
Josh Soref
e7728fdc94 spelling: log-in 2019-09-11 19:25:44 -04:00
Josh Soref
052122e4d0 spelling: abuse 2019-09-11 19:25:29 -04:00
Josh Soref
38827d2b3d grammar: period at end of sentence (not inside parenthetical) 2019-09-11 19:25:19 -04:00
Liam Newman
9e1f16be27 Fix OkHttpConnector caching 2019-09-10 23:01:50 -07:00
Liam Newman
c845846317 Do not rerun tests
If they failed once, they will fail again.
2019-09-10 23:00:44 -07:00
Liam Newman
9276556f19 Mockito 3.0.0 2019-09-10 22:59:07 -07:00
Liam Newman
c796d18948 Merge pull request #541 from bitwiseman/wiremock-github-rule
Add GitHubApiWireMockRule
2019-09-10 22:54:27 -07:00
Liam Newman
8dee5520cf Add GitHubApiWireMockRule
Separates the WireMock and GitHub API info from project specific code.
2019-09-10 22:42:28 -07:00
Liam Newman
440e13714e Merge branch 'master' into issue_466_edit_gists 2019-09-09 22:04:11 -07:00
Liam Newman
44a70b372d Merge pull request #502 from CodeAndChoke/hashcode_equals
Added equals and hashcode
2019-09-09 22:02:22 -07:00
Liam Newman
504286e96e Merge pull request #540 from bitwiseman/test-run
Working CI Build
2019-09-09 22:01:33 -07:00
Liam Newman
ffdd54d2fa Merge branch 'master' into get-user-orgs 2019-09-09 19:40:00 -07:00
Liam Newman
32804b81c0 Merge pull request #527 from WouterG/patch-1
Remove unnessesairy "throws"
2019-09-09 19:38:09 -07:00
Liam Newman
403b22ade0 Working CI Build
This change automatically turns off tests where we haven't had a chance to implement wiremocking.
They can still be run locally by setting test.github.useProxy (even though most of them do actually use the proxy).
2019-09-09 19:34:09 -07:00
Liam Newman
a4e74abcca Merge branch 'master' into master 2019-09-09 17:19:58 -07:00
Liam Newman
8dcef5bac0 Merge branch 'master' into draft-pr 2019-09-09 16:57:14 -07:00
Liam Newman
49878bc4e3 Merge branch 'master' into patch-1 2019-09-09 16:56:34 -07:00
Liam Newman
3f1a71c8a4 Merge branch 'master' into request-log 2019-09-09 16:54:24 -07:00
Liam Newman
bf9b2c0da3 Merge branch 'master' into team-pr-review-requests 2019-09-09 16:40:00 -07:00
Liam Newman
909a274709 Merge pull request #538 from ewiegs4/pr-query-head
Namespace PR head queries with repo's owner by default
2019-09-09 16:31:21 -07:00
Liam Newman
fc529b8083 Merge remote-tracking branch 'kohsuke/master' into pr-query-head 2019-09-09 16:16:36 -07:00
Liam Newman
f1386f26fb maven-build.yml
Trying to get actions to trigger
2019-09-09 16:15:35 -07:00
Liam Newman
cccd09d329 Delete maven.yml 2019-09-09 16:13:51 -07:00
Liam Newman
0fccf7effe Update maven.yml 2019-09-09 16:06:21 -07:00
Liam Newman
4b91a47c8b Merge branch 'master' into issue_460_team_description_field 2019-09-09 16:01:27 -07:00
Liam Newman
bd40499bbe Improve behavior and documentation for WireMock testing 2019-09-09 15:55:03 -07:00
Liam Newman
c7c8cd76c6 Merge branch 'master' into label-description 2019-09-08 23:58:18 -07:00
Liam Newman
0bb9f0ce41 Merge branch 'master' into pr-query-head 2019-09-08 23:55:34 -07:00
Liam Newman
7136afce8e Update all WireMock data files 2019-09-08 23:33:44 -07:00
Liam Newman
ec17c1de6a Update PullRequestTest for WireMocking 2019-09-08 23:33:30 -07:00
Liam Newman
8d6daef354 Rewrite wiremock rule to snapshot on a per-method basis 2019-09-08 23:33:30 -07:00
Liam Newman
3a09d2de4a Rename README to README.md 2019-09-06 17:07:13 -07:00
Liam Newman
c78e10f92e Merge remote-tracking branch 'kohsuke/master' into pr-query-head 2019-09-06 16:18:49 -07:00
Liam Newman
b113ff35ac Merge pull request #537 from bitwiseman/wiremock
Add WireMock testing facility
2019-09-06 16:17:37 -07:00
Eddie Wiegers
6360024d20 Add test for qualified case. 2019-09-06 16:43:19 -05:00
Martin van Zijl
a7683f6bd7 Added setter and unit tests for GHTeam description field. 2019-09-05 16:23:38 +12:00
Liam Newman
e46a9f3f2a Java 8 required for testing, not for package 2019-09-03 13:16:28 -07:00
Eddie Wiegers
a8d711d4c8 Qualify PR head queries with repo's owner by default 2019-09-03 11:40:33 -05:00
Liam Newman
df74fc67bd Add WireMock tests to CI 2019-08-31 21:55:09 -07:00
Liam Newman
450261abbf Move scenario to json files 2019-08-31 19:52:50 -07:00
Liam Newman
12230edc54 Add UserTest to WireMock 2019-08-31 01:35:21 -07:00
Liam Newman
d1cfcf561b Converted GistTest to WireMock 2019-08-31 01:25:25 -07:00
Liam Newman
d143f5af8b Start of WireMock 2019-08-30 17:07:17 -07:00
Liam Newman
0f7ae3cda7 Merge pull request #534 from res0nance/https
Swap to HTTPs
2019-08-28 13:24:52 -07:00
Raihaan Shouhell
baf94e56c8 Swap to HTTPs 2019-08-27 10:45:02 +08:00
Paulo Miguel Almeida
905bd1a4c9 Fix typo
Signed-off-by: Paulo Almeida <paulo.miguel.almeida.rodenas@gmail.com>
2019-08-26 12:37:28 +12:00
Paulo Almeida
96bcf24047 Merge branch 'master' of https://github.com/kohsuke/github-api
# Conflicts:
#	pom.xml
2019-08-26 12:31:23 +12:00
Liam Newman
dfe47235cf Update maven.yml 2019-08-23 19:11:16 -07:00
Liam Newman
b82ea8eaa8 Merge pull request #533 from sullis/jackson-2.9.9.3
jackson-databind 2.9.9.3
2019-08-23 19:06:25 -07:00
Liam Newman
b1b830c268 Switch to spotbugs 2019-08-23 19:02:14 -07:00
Liam Newman
e654d4a6df Fix pom warnings 2019-08-23 18:48:49 -07:00
Liam Newman
ac30b17ecb Do no run GMaven on this project 2019-08-23 18:45:03 -07:00
Liam Newman
95efdb3a51 Use newer dependency plugin 2019-08-23 18:35:38 -07:00
Liam Newman
49c165e203 Update maven.yml 2019-08-23 18:24:52 -07:00
Liam Newman
a4be351d9f Update maven.yml 2019-08-23 18:20:36 -07:00
Liam Newman
3d0401aecd Update maven.yml 2019-08-23 18:17:34 -07:00
Liam Newman
7c27572a53 Split out dependency downloading to new step
For visualization, it helps to not have to search through all the dependency downloads
2019-08-23 18:17:17 -07:00
Liam Newman
1e7760012e Merge pull request #476 from turbanoff/patch-1
Provide more exception details
2019-08-23 18:12:34 -07:00
Liam Newman
24d464b6e5 Add github build action
This ensures that PR's at least build
Currently runs no tests, since they all depend on having user level access to github
2019-08-23 18:10:38 -07:00
Sean Sullivan
499d91f9f8 jackson-databind 2.9.9.3 2019-08-15 15:23:42 -04:00
Matt Farmer
8e0ceaa06b Add a test for requesting reviewers 2019-08-10 20:52:55 -04:00
Matt Farmer
4e62641f7e Add ability to get requested teams 2019-08-10 20:46:34 -04:00
Matt Farmer
688644f5a4 Add support for requesting teams review prs 2019-08-10 20:31:15 -04:00
Paulo Miguel Almeida
4703f2d1f5 Add tests for GithubApp integration;
Add wiremock-standalone library;

Signed-off-by: Paulo Almeida <paulo.miguel.almeida.rodenas@gmail.com>
2019-08-10 19:01:12 +12:00
Artem V. Navrotskiy
14149ae949 Add GitHub API requests logging 2019-07-19 12:00:48 +03:00
Wouter Gerarts
a0fb0d170c Remove unnessesairy "throws"
All IOExceptions are already caught within the method itself.
2019-07-12 17:46:34 +02:00
Vincent Behar
e133afec86 Add support for draft pull requests
See https://developer.github.com/v3/pulls/#input
and https://help.github.com/en/articles/about-pull-requests#draft-pull-requests

Note that it requires the use of a github api preview: https://developer.github.com/v3/previews/#draft-pull-requests
2019-07-11 17:12:20 +02:00
Liam Newman
3ae8ee8ddb Merge pull request #498 from rmetzger/fix-450
Add GHPullRequestReview.submitted_at field
2019-07-01 10:32:01 -07:00
Liam Newman
012643a231 Merge pull request #413 from ThomasCookOnline/fix_version
fix issues
2019-06-19 17:11:59 -07:00
Liam Newman
dccb43f4dc Merge pull request #517 from jamesatha/repo-by-id
Adds the ability to get a repository by ID
2019-06-19 17:11:03 -07:00
Paulo Almeida
15b3bc6a63 Remove JWT dependencies used for testing purposes 2019-06-18 13:36:00 +12:00
Paulo Almeida
2d15bef76d Add missing CHECK_SUITE github event 2019-06-18 11:24:59 +12:00
Paulo Almeida
756d298f04 Add missing INTEGRATION_INSTALLATION_REPOSITORIES github event 2019-06-18 10:50:08 +12:00
Paulo Almeida
9f35eb1a85 Add @Preview and @Deprecated annotations to methods in which the API is still in preview 2019-06-12 11:32:03 +12:00
Paulo Almeida
c905bb4b6c Implement GitHub App API methods 2019-06-11 17:27:07 +12:00
Austin Witt
c78af01c8f Added two getUserPublicOrganizations(...) methods to get public Org memberships of any user, not just the currently-authenticated one. 2019-05-23 09:08:18 -05:00
Austin Witt
084855645a Due-diligence & hygiene updates to GitHub.java 2019-05-23 09:03:47 -05:00
Liam Newman
afce9ece89 Merge pull request #507 from ingwarsw/add_get_team_by_id
Add getTeam by id function
2019-05-22 15:22:25 -07:00
Liam Newman
154e50e36d Merge pull request #499 from anatolyD/feature/let-create-pr-to-org-fork
Create PR from original repo to private org fork
2019-05-22 14:55:52 -07:00
Liam Newman
80a129102b Merge pull request #492 from arykov/fix_add_team_member_role_capital
fixed membership role problem with case
2019-05-17 14:03:43 -07:00
Liam Newman
93672a074e Merge pull request #508 from blacelle/mindthecode-2019-03-24
Update maven dependency
2019-05-16 19:32:04 -07:00
Liam Newman
c7f6f6233c Merge pull request #485 from scotty-g/remove-console-logging
remove system.out from listOrgs
2019-05-16 18:56:45 -07:00
Liam Newman
68915a9daf Added tests for createLabel() method 2019-05-16 18:51:44 -07:00
Liam Newman
13eb91f8dd Preserve api compatibility for createLabel() 2019-05-16 18:44:39 -07:00
Liam Newman
1a8355e6fb Merge branch 'master' into fix_version 2019-05-16 18:23:59 -07:00
James Athappilly
aa2b7ae60a Adds the ability to get a repository by ID
Fixes: https://github.com/kohsuke/github-api/issues/515
2019-04-26 00:29:26 -07:00
Benoit Lacelle
acd36b7ea5 Update maven dependency versions 2019-03-24 12:55:40 +00:00
Karol Lassak
87245ab79f Add getTeam by id function 2019-03-18 14:15:29 +01:00
Long Nguyen
13b6a17827 Added equals and hashcode 2019-03-07 01:08:56 +01:00
Anatoly Danilov
615e4cf24e Create PR is possible without the owner of the repo to modify PR.
Use case: when fork is done into private organization then the original repo maintainer can't have any access there hence this field has to be set to `false` explicitly
2019-02-20 09:25:35 +03:00
Robert Metzger
0e6d08f027 Add GHPullRequestReview.submitted_at field 2019-02-19 10:13:21 +01:00
Alex Rykov
d593e584dd fixed membership role problem with case 2019-02-01 12:19:28 -05:00
sg012265
e046b97160 remove system.out from listOrgs 2018-12-22 21:31:33 -06:00
Martin van Zijl
567d3dac55 Add support for editing Gists.
Fixes issue #466

NOTE: I could not get the deleteFile() method to work.
2018-12-20 08:16:25 +13:00
Martin van Zijl
a67a0aa924 Add method to invite user to organization.
Fixes issue #467
2018-12-14 07:18:29 +13:00
Турбанов Андрей
1b1e3e88fe Provide more exception details
For now if invalid credentials used to search github-api throws following exception

    Exception in thread "main" org.kohsuke.github.GHException: Failed to retrieve https://api.github.com/search/repositories?q=vk+language%3Ajava+created%3A2015-11-26..2016-11-26
	at org.kohsuke.github.Requester$PagingIterator.fetch(Requester.java:529)
	at org.kohsuke.github.Requester$PagingIterator.hasNext(Requester.java:494)
	at org.kohsuke.github.PagedSearchIterable$1.hasNext(PagedSearchIterable.java:55)
	at org.kohsuke.github.PagedIterator.fetch(PagedIterator.java:44)
	at org.kohsuke.github.PagedIterator.hasNext(PagedIterator.java:32)

There is no mentions if credentials at all. Better to propagate exception to user to be able to deal with it.
2018-11-26 01:21:28 +03:00
Immanuel Washington
ec99636ef0 Adding Label description property
Label in the GitHub API has an optional field description which had not been implemented.
2018-11-25 02:10:06 -05:00
Martin van Zijl
9d955d252a Add statistics API.
Fixes issue #330
2018-11-16 18:24:30 +13:00
Martin van Zijl
f136f6837a Added description field to GHTeam class.
Fixes issue #460.
2018-11-13 07:37:07 +13:00
Martin van Zijl
6fc1fb0966 Added a method to list authorizations.
Fixes issue #459
2018-11-12 17:50:49 +13:00
Kohsuke Kawaguchi
fad203a66d [maven-release-plugin] prepare for next development iteration 2018-11-06 08:42:28 -08:00
Kohsuke Kawaguchi
c1bab63ebd [maven-release-plugin] prepare release github-api-1.95 2018-11-06 08:42:18 -08:00
Kohsuke Kawaguchi
40f012b03c rtyler no longer has 50 people he follows 2018-11-06 08:35:48 -08:00
Kohsuke Kawaguchi
a380059389 Merge branch 'master' of github.com:kohsuke/github-api 2018-11-06 08:16:06 -08:00
Kohsuke Kawaguchi
24b998ba2d Merge pull request #461 2018-11-06 08:15:11 -08:00
Kohsuke Kawaguchi
9a1bb09c9f Massaging the changes.
In particular, avoid the kind of addLabel() method that has lots of side
effect and do multiple things.
2018-11-06 08:14:12 -08:00
Kohsuke Kawaguchi
3ad66f8937 Merge pull request #468 from KostyaSha/fixMemLeak
Fix memory leak.
2018-11-06 07:56:15 -08:00
Kohsuke Kawaguchi
a6f3e7df55 Merge pull request #464 2018-11-06 07:49:17 -08:00
Kohsuke Kawaguchi
9345d3be31 Follow the convention in this library 2018-11-06 07:49:02 -08:00
Kohsuke Kawaguchi
8e85bf8839 Merge pull request #470 from recena/archived-attr
Added archived attribute in GHRepository
2018-10-29 08:28:00 -07:00
Manuel Recena
1012dcd194 Added archived attribute in GHRepository. Updated the parent POM 2018-10-25 11:24:46 +02:00
Kanstantsin Shautsou
70251ea11e Fix memory leak.
While repository object is active and code requests commits they are stored in Map.
GHCommit.files contains huge String[]/char[]  amount of data.
The same could be applied to Milestones.
2018-10-20 19:13:47 +03:00
I329802 (Xeric)
9381471fbd add request reviewers as attribute of GHPullRequest 2018-10-11 17:30:25 +08:00
Even Holthe
1c4b716f1a Add methods for adding/removing labels to GHIssue
Fixes #456
2018-10-01 23:29:15 +02:00
Kohsuke Kawaguchi
c8b0584127 [maven-release-plugin] prepare for next development iteration 2018-08-29 21:05:31 -07:00
Kohsuke Kawaguchi
5194a361f4 [maven-release-plugin] prepare release github-api-1.94 2018-08-29 21:05:21 -07:00
Kohsuke Kawaguchi
c44e5d2a87 findbugs fix 2018-08-29 21:00:24 -07:00
Kohsuke Kawaguchi
ee4d514b66 close an opened stream 2018-08-29 20:48:44 -07:00
Kohsuke Kawaguchi
863995cb50 findbugs warning fix 2018-08-29 20:48:36 -07:00
Kohsuke Kawaguchi
cbfe72a76e Fixed a broken test 2018-08-29 20:31:44 -07:00
Kohsuke Kawaguchi
4f17d3519c Merge pull request #411 from tadfisher/master
Add GHRepository.getRelease and GHRepository.getReleaseByTagName
2018-08-30 05:22:26 +02:00
Kohsuke Kawaguchi
3cfcad76ac Merge pull request #417 from twcurrie/tcurrie/revisions
Added release payload.
2018-08-30 05:21:24 +02:00
Kohsuke Kawaguchi
1ca6535811 Merge pull request #449 from martinvanzijl/issue_426_fix_nullptr_when_deleting_refs
Fix for issue #426. Fix null pointer when deleting refs.
2018-08-30 05:21:09 +02:00
Kohsuke Kawaguchi
53612ad2e4 Merge pull request #446 from daniel-beck/fix-page-size
Fix pagination for APIs that supported it ad hoc
2018-08-30 05:20:53 +02:00
Kohsuke Kawaguchi
4b799d264c Merge pull request #443 from Arrow768/GHEventPayload_Issue
Adds the GHEventPayload.Issue class
2018-08-30 05:20:26 +02:00
Kohsuke Kawaguchi
ca5594703a Merge pull request #439 from l3ender/master
Add support for repository searching by "topic"
2018-08-30 05:20:03 +02:00
Kohsuke Kawaguchi
7fc2d9dcca Merge remote-tracking branch 'origin/master' 2018-08-29 20:19:14 -07:00
Kohsuke Kawaguchi
c413fc1e30 Merge pull request #438 from jgangemi/jae/issue-434
- added overloaded 'uploadAsset' method
2018-08-30 05:18:51 +02:00
Kohsuke Kawaguchi
b5086c7759 Merge pull request #437 2018-08-29 20:18:21 -07:00
Kohsuke Kawaguchi
92a015ca4d Clear up import statements 2018-08-29 20:18:10 -07:00
Kohsuke Kawaguchi
3b2802e36d minor doc improvement 2018-08-29 20:18:00 -07:00
Kohsuke Kawaguchi
7bf23eaa15 Merge pull request #436 from jgangemi/jae/rm-exception
- remove unthrown IOException
2018-08-30 05:16:28 +02:00
Kohsuke Kawaguchi
9afd1c5ee8 Merge pull request #435 2018-08-29 20:15:08 -07:00
Kohsuke Kawaguchi
5e36377b36 It appears LOKI preview is done and all those methods are now final 2018-08-29 20:15:01 -07:00
Kohsuke Kawaguchi
c988df13a8 Use a short form 2018-08-29 20:15:01 -07:00
Kohsuke Kawaguchi
29a40d31b7 TAB -> space 2018-08-29 20:15:01 -07:00
Kohsuke Kawaguchi
ddc27e818b Let's not yet expose this new class because it's not final 2018-08-29 20:15:01 -07:00
Kohsuke Kawaguchi
3fa70ac841 doc improvement 2018-08-29 19:05:56 -07:00
Kohsuke Kawaguchi
b2b7dfaf37 Massaged the change to match the existing API design convention 2018-08-29 19:05:19 -07:00
Martin van Zijl
c309c2cf13 Fix for issue #426. Fix null pointer when deleting refs. 2018-08-13 12:36:15 +12:00
Martin van Zijl
71304b114a Fix for issue #376. Added issue events API. 2018-08-13 11:44:21 +12:00
Daniel Beck
0ffcbdbd38 Fix pagination for APIs that supported it ad hoc 2018-07-17 11:27:54 +02:00
Werner
e368a17420 Adds the GHEventPayload.Issue class 2018-07-01 12:23:13 +02:00
Sharath
2fcfb2f67d address review comments in supporting updating content with sha 2018-06-12 18:26:20 -07:00
onoguera-ob
f68a85056e Update integration test. 2018-06-12 18:26:20 -07:00
Oliver Noguera
943f47d29d Add sha1 to updateFiles see
https://developer.github.com/v3/repos/contents/#update-a-file
2018-06-12 18:26:20 -07:00
l3ender
fd37a2c466 Add support for repository searching by "topic"
See https://help.github.com/articles/searching-repositories/#search-by-topic
2018-06-06 11:44:46 -05:00
Jae Gangemi
eacdd7afe8 - added overloaded 'uploadAsset' method 2018-05-30 08:18:25 -06:00
Rechi
fe5ea52cdf [feature] implement Repository Invitations API
fixes #374
2018-05-29 22:00:00 +02:00
Jae Gangemi
ca6d77cbb3 - remove unthrown IOException 2018-05-28 17:49:21 -06:00
Jae Gangemi
1145941d11 - add support for signed commits
- add support for required number of reviews
2018-05-27 15:33:58 -06:00
Kohsuke Kawaguchi
d61697a152 [maven-release-plugin] prepare for next development iteration 2018-05-01 07:56:38 -07:00
Kohsuke Kawaguchi
38b77a9c79 [maven-release-plugin] prepare release github-api-1.93 2018-05-01 07:56:27 -07:00
Kohsuke Kawaguchi
7d294ee8c2 Looks like release rollback didn't quite complete 2018-05-01 07:26:09 -07:00
Kohsuke Kawaguchi
33d9422d03 Merge pull request #422 from ggrell/fix-421-enum-case-issue
Fixes #421 - Enum case doesn't match for Pull Request Reviews
2018-05-01 07:19:42 -07:00
Kohsuke Kawaguchi
bb7302c23a Merge branch 'master' of github.com:kohsuke/github-api 2018-05-01 07:18:57 -07:00
Kohsuke Kawaguchi
d50ae63a5a Merge pull request #431 from Rechi/fixPRLabels
[fix] fetch labels with HTTP GET method
2018-05-01 07:18:43 -07:00
Kohsuke Kawaguchi
1961836e19 Merge pull request #427 from itepikin-smartling/master
Add support for previous_filename for file details in PR.
2018-05-01 07:17:32 -07:00
Kohsuke Kawaguchi
f2ed7c15ce Looks like the permission scheme changed on jenkinsci/violations-plugin 2018-05-01 07:12:30 -07:00
Kohsuke Kawaguchi
4dce173630 Extracted the List<GHUser>->List<String> out to Requester for reuse 2018-05-01 07:03:53 -07:00
Kohsuke Kawaguchi
86f868b2d4 Fixed compilation errors introduced by 8b38a20c18 2018-05-01 06:59:03 -07:00
Kohsuke Kawaguchi
363064f5c0 Merge branch 'master' of github.com:kohsuke/github-api 2018-04-30 19:58:33 -07:00
Kohsuke Kawaguchi
9d99ee9cfc Merge pull request #430 from twcurrie/tcurrie/requestReviewer
Added request reviewers function within GHPullRequest.
2018-04-30 19:58:19 -07:00
Rechi
db8969707d [fix] fetch labels with HTTP GET method 2018-04-06 10:00:00 +02:00
Trevor Currie
a24ac37dfd Added request reviewers function within GHPullRequest. 2018-03-28 23:33:08 -07:00
itepikin
1b04d471b3 Added support for previous_filename for file details in PR. 2018-03-22 11:16:09 +03:00
Gyuri Grell
9cc400a081 Fixes #421 - Enum case doesn't match for Pull Request Reviews
* Set Jackson to ignore case differences in enums.
2018-03-01 20:50:00 -05:00
Kohsuke Kawaguchi
e233aeec0c Merge pull request #410 from Limess/409/update-commons-lang
Update commons-lang to 3.7
2018-03-01 09:45:15 -08:00
Kohsuke Kawaguchi
5dfd621900 Merge pull request #420 from randomvariable/fix/tlsv12
OkHttpConnector: Enforce use of TLSv1.2 to match current Github and Github Enterprise TLS support.
2018-03-01 09:43:24 -08:00
Naadir Jeewa
f0f6a9988f OkHttpConnector: Enforce use of TLSv1.2 to match current Github
and Github Enterprise TLS support.
2018-02-28 09:36:15 +00:00
Trevor Currie
587438938c Added release payload. 2018-02-22 09:38:25 -08:00
Edem Osmanov
2497ac68d1 fix issues 2018-02-14 12:16:01 +02:00
Tad Fisher
75918c59cc Add GHRepository.getRelease and GHRepository.getReleaseByTagName
These implement the API endpoints for:

- GET /repos/:owner/:repo/releases/:id
- GET /repos/:owner/:repo/releases/tags/:tag
2018-02-05 14:30:24 -08:00
Charlie Briggs
8b38a20c18 Update commons-lang to 3.7
This fixes the vulnerabilities:
* https://issues.apache.org/jira/browse/LANG-1373
* https://issues.apache.org/jira/browse/LANG-805.
2018-01-23 11:00:58 +00:00
Kohsuke Kawaguchi
e7b76bfdc5 Doc improvements 2018-01-21 11:51:04 -08:00
Kohsuke Kawaguchi
3503ff6d36 Additional methods for issue comment 2018-01-21 11:50:22 -08:00
Kohsuke Kawaguchi
192e21a9fc [maven-release-plugin] prepare for next development iteration 2018-01-13 11:52:05 -08:00
Kohsuke Kawaguchi
24e288d584 [maven-release-plugin] prepare release github-api-1.92 2018-01-13 11:51:56 -08:00
Kohsuke Kawaguchi
0e5ffda5e5 Release failed due to javadoc errors 2018-01-13 11:45:57 -08:00
Kohsuke Kawaguchi
cdf6f18ec0 [maven-release-plugin] prepare for next development iteration 2018-01-13 10:36:53 -08:00
Kohsuke Kawaguchi
188245fa7f [maven-release-plugin] prepare release github-api-1.91 2018-01-13 10:36:45 -08:00
Kohsuke Kawaguchi
e10b747d6a Re-retried the object.
It looks like the format has changed a bit since this payload was
retrieved originally?
2018-01-13 10:30:48 -08:00
Kohsuke Kawaguchi
f2bb6a05a5 Merge pull request #384 2018-01-13 10:19:12 -08:00
Kohsuke Kawaguchi
f41da19db5 Further restoration of the compatibility 2018-01-13 09:54:14 -08:00
Kohsuke Kawaguchi
d0a56dbb21 Merge pull request #406
... with some further changes
2018-01-13 09:47:37 -08:00
Kohsuke Kawaguchi
acbf286e59 Massaged the changes
- Restored binary compatibility. The draft API has changed in some
  significant way when it became public, and the PR took the liberty to
  delete removed constants and method signatures. I brought them back so
  that older clients can keep functioning.

- Introduced a builder pattern to create PR review

- replying to a review comment should be an instance method, not a
  static method.

- GHPullRequestReview and GHPullRequestReviewDraft was not making sense
  to me, since GitHub API doesn't differentiate them. It creates a
  practical problem of not being able to submit a review comment unless
  you created the review comment in the same JVM session. That said, I
  don't understand the point of this two phase approach in the GitHub
  API to begin with!
2018-01-13 09:43:44 -08:00
Kohsuke Kawaguchi
0f7c160409 Based on issue #399, adjusting the behaviour.
This ends up changing the behaviour cloes to that of #394.
2018-01-12 21:33:03 -08:00
Kohsuke Kawaguchi
5113aacb89 Issue #403: Typo in method name 2018-01-12 21:28:37 -08:00
Kohsuke Kawaguchi
4e31636181 Allow the caller to wait for the mergeable state to change.
This approaches #394 differently. The problem with the original #394 is
that the supposed behaviour is only useful for people waiting for
`getMergeable()` to return non-null in a busy loop, yet it impacts all
the other methods of this object.
2018-01-12 21:25:30 -08:00
Kohsuke Kawaguchi
1e497d2c44 Merge branch 'master' into bridge-method-annotation 2018-01-12 21:13:49 -08:00
Kohsuke Kawaguchi
70bd4fa161 Merge pull request #379 2018-01-12 21:12:48 -08:00
Kohsuke Kawaguchi
65996050d5 Massaged changes to follow the convention 2018-01-12 21:12:40 -08:00
Kohsuke Kawaguchi
7f52031199 Merge branch 'master' of github.com:kohsuke/github-api 2018-01-12 21:07:11 -08:00
Kohsuke Kawaguchi
5430f3d33c Merge pull request #391 2018-01-12 21:06:55 -08:00
Kohsuke Kawaguchi
43075faaf8 By convention we use "listXyz" method names 2018-01-12 21:06:47 -08:00
Kohsuke Kawaguchi
f3a1272e31 Merge pull request #397 from mizoguche/set-milestone
Add GHIssue#setMilestone
2018-01-12 21:04:18 -08:00
Kohsuke Kawaguchi
41c028d4d9 Merge pull request #401 2018-01-12 21:00:56 -08:00
Kohsuke Kawaguchi
a17ce04552 Adjustment to compensate 2018-01-12 21:00:25 -08:00
Björn Häuser
d0b4652dcd Replace "new Error" with GHException
(rolled back some of the hunks from the original PR)
2018-01-12 19:44:25 -08:00
Kohsuke Kawaguchi
e66f71c76e Merge pull request #407 from notsudo/GHCreateRepositoryBuilder_Add_Merge_Settings
Adding merge settings to GHCreateRepositoryBuilder
2018-01-12 19:39:03 -08:00
Kohsuke Kawaguchi
6effd4b846 Merge pull request #396 from Rechi/fixGHPersonNullPointer
[fix] GHPerson: check if root is null
2018-01-12 08:45:02 -08:00
Timothy McNally
df861f5403 Adding methods to GHCreateRepositoryBuilder to allow setting the allowed merge methods for pull requests. 2018-01-09 17:32:54 -08:00
Sébastien Lesaint
e74346fed6 support create PR review in single API call & remove @Preview 2018-01-09 14:13:25 +01:00
Sébastien Lesaint
6961c467a6 create review comment reply from GHPullRequest 2018-01-09 14:13:25 +01:00
Sébastien Lesaint
892d305165 add Requester#with override for long value 2018-01-09 14:13:25 +01:00
Sébastien Lesaint
fa16261d7a position of pr comment can be null and original_position is not parsed
position of pr comment is null when comment is outdated (ie. not located in diff patch anymore)
2018-01-09 14:13:25 +01:00
Sébastien Lesaint
15991fd2f7 PullRequest review state and event do not have same values
this fixes parsing of response of WS call submitting a review to fail
when event of new review is REQUEST_CHANGES
also, specifying event when creating a pending PR review is useless and
providing it when submitting the review is enough
2018-01-09 14:13:25 +01:00
Michiaki Mizoguchi
c80b8f60f8 Add GHIssue#setMilestone 2017-11-16 12:42:52 +09:00
Rechi
ab6253cbd0 [fix] GHPerson: check if root is null 2017-11-09 22:41:49 +01:00
sg012265
35ba267115 Revert wildcard usage for imports 2017-10-30 15:38:19 -05:00
sg012265
ab24e6e1c1 Add get for all orgs 2017-10-30 15:32:25 -05:00
Kohsuke Kawaguchi
e25ae27a15 [maven-release-plugin] prepare for next development iteration 2017-10-28 15:54:44 -07:00
Kohsuke Kawaguchi
2b7c524908 [maven-release-plugin] prepare release github-api-1.90 2017-10-28 15:54:33 -07:00
Kohsuke Kawaguchi
0b069df9ce Pick up the version that fixes int->long adaption 2017-10-28 15:48:26 -07:00
Kohsuke Kawaguchi
60c9ba88ae Updated tests 2017-10-28 15:27:38 -07:00
Kohsuke Kawaguchi
cc2e60c84a Merge pull request #388 2017-10-28 09:01:01 -07:00
Kohsuke Kawaguchi
83c2c4e92e Fixed the broken design of how GHDeploymentStatus get exposed. 2017-10-28 08:59:41 -07:00
Kohsuke Kawaguchi
ab3d9e82ef A little better version of the bridge method 2017-10-28 08:43:48 -07:00
Kohsuke Kawaguchi
b6063dd534 Restored binary compatibility 2017-10-28 08:42:27 -07:00
Kohsuke Kawaguchi
e6754354e4 Merge pull request #389 2017-10-28 07:54:47 -07:00
Kohsuke Kawaguchi
4849619d67 None of the connectToEnterprise methods are preferrable so document accordingly 2017-10-28 07:54:41 -07:00
Kohsuke Kawaguchi
9b0ace242a Merge pull request #390 2017-10-28 07:45:14 -07:00
Kohsuke Kawaguchi
e94ba74058 Convention is to call these methods setXyz. Plus doc 2017-10-28 07:44:23 -07:00
Baptiste Mathus
569fa06d2d Labels: add method to update color 2017-10-25 14:06:28 +02:00
iraleigh
46dce17abc Fixed Typo 2017-10-24 14:53:23 -07:00
iraleigh
40d8f4a352 Fixed OAuth connection to enterprise API 2017-10-24 14:24:25 -07:00
Arne Burmeister
6415785220 boyscout: updated dependencies 2017-10-23 17:05:31 +02:00
Arne Burmeister
7735edeae8 extend id from int to long 2017-10-23 17:05:02 +02:00
Matt Nelson
0f81d1dbb3 Add support for pr review/review comment events 2017-10-05 18:14:15 -05:00
Anton Zagorskii
ae1ec8b558 Roles for team members 2017-09-20 13:22:30 +01:00
Jesse Glick
09c2b39530 bridge-method-annotation should be an optional dep. 2017-09-13 15:14:42 -04:00
Kohsuke Kawaguchi
b443e866f9 Added lock/unlock op and additional properties
Issue #355
2017-09-09 20:38:40 -07:00
Kohsuke Kawaguchi
d4404713a8 [maven-release-plugin] prepare for next development iteration 2017-09-09 13:28:40 -07:00
Kohsuke Kawaguchi
47409a9a99 [maven-release-plugin] prepare release github-api-1.89 2017-09-09 13:28:31 -07:00
Kohsuke Kawaguchi
60bfea2d3b Bug fix 2017-09-09 13:22:16 -07:00
Kohsuke Kawaguchi
d3ed8eaed5 Merge pull request #339 2017-09-09 13:07:18 -07:00
Kohsuke Kawaguchi
692dccf110 Massaging the change a bit 2017-09-09 13:03:18 -07:00
Kohsuke Kawaguchi
92caf98683 Reverting java1.6 change which I assume is accidental.
Not that I really care about Java5 but I think that change should
be done separatel & intentionally
2017-09-09 12:57:52 -07:00
Kohsuke Kawaguchi
6178d38895 connector usage is unsynchronized 2017-09-09 12:47:18 -07:00
Kohsuke Kawaguchi
40fb38a9ba Window focus problem 2017-09-09 12:45:58 -07:00
Kohsuke Kawaguchi
20e68d53fd Merge pull request #283 2017-09-09 12:45:02 -07:00
Kohsuke Kawaguchi
2d3557e049 Improved the intern logic
if the user record does not exist yet, there's no need to fetch that
eagerly, as they are fetched on demand via the populate() method.
2017-09-09 12:44:12 -07:00
Kohsuke Kawaguchi
d8f4bc7395 Added updater
This solves #331 differently
2017-09-09 12:31:10 -07:00
Kohsuke Kawaguchi
353f9bb809 pointless null check since the with method already does it 2017-09-09 12:23:40 -07:00
Kohsuke Kawaguchi
ccfe3ad4f7 Merge pull request #333 2017-09-09 12:17:39 -07:00
Kohsuke Kawaguchi
9012820c03 Massage the signature a bit.
AFAICT sha and merge_method are not mutually exclusive.
2017-09-09 12:17:21 -07:00
Kohsuke Kawaguchi
fe2af19e42 Unused constant 2017-09-09 12:15:21 -07:00
Kohsuke Kawaguchi
f721e053f1 Added convenience connector for OkHttp3
Note that the existing one needs to be kept for compatibility with OkHttp2
2017-09-09 12:11:36 -07:00
Kohsuke Kawaguchi
e6ad9feb84 Keeping Findbugs happy 2017-09-09 12:05:39 -07:00
Kohsuke Kawaguchi
635350c40e Additional naming consistency change 2017-09-09 12:02:44 -07:00
Kohsuke Kawaguchi
17edd33703 Reorganized imports following #337 2017-09-09 12:00:23 -07:00
Kohsuke Kawaguchi
b0f2a871c6 Merge pull request #337 2017-09-09 11:58:13 -07:00
Kohsuke Kawaguchi
8928a8a1dc Content type should be JSON by default when sending JSON.
This solves #350 a little differently.
2017-09-09 11:51:55 -07:00
Kohsuke Kawaguchi
2b6f37a6cc Merge pull request #361 2017-09-09 11:48:33 -07:00
Kohsuke Kawaguchi
f3a3b87861 Defined entry points 2017-09-09 11:48:25 -07:00
Kohsuke Kawaguchi
9cf6ee78d4 Pointless string conversion 2017-09-09 11:44:09 -07:00
Kohsuke Kawaguchi
bbc2f3962f Proper access control modifier 2017-09-09 11:44:02 -07:00
Kohsuke Kawaguchi
be49eb22d2 Merge pull request #368 2017-09-09 11:40:41 -07:00
Kohsuke Kawaguchi
fb47067215 Naming changes to emphasize that these are just traffic info 2017-09-09 11:40:28 -07:00
Kohsuke Kawaguchi
2c80ef178d Capture commonality between total and daily 2017-09-09 11:39:12 -07:00
Kohsuke Kawaguchi
9af8112148 Tightening up access control and use primitive type 2017-09-09 11:37:18 -07:00
Kohsuke Kawaguchi
57c36f437a [maven-release-plugin] prepare for next development iteration 2017-09-09 08:19:29 -07:00
Kohsuke Kawaguchi
5ed8a34566 [maven-release-plugin] prepare release github-api-1.88 2017-09-09 08:19:20 -07:00
Kohsuke Kawaguchi
ea8df9bd61 javadoc fix 2017-09-09 08:13:51 -07:00
Kohsuke Kawaguchi
b0c51e03b7 [maven-release-plugin] prepare for next development iteration 2017-09-09 08:06:27 -07:00
Kohsuke Kawaguchi
336924ef23 [maven-release-plugin] prepare release github-api-1.87 2017-09-09 08:06:18 -07:00
Kohsuke Kawaguchi
ad28ca4a90 Use string constant like other previews 2017-09-09 07:59:31 -07:00
Kohsuke Kawaguchi
aebbe86cfc Keeping findbugs happy 2017-09-09 07:57:49 -07:00
Kohsuke Kawaguchi
df9faf4943 Auto-retry flaky tests 2017-09-08 16:09:41 -07:00
Kohsuke Kawaguchi
3e295b6be4 Merge branch 'master' of github.com:kohsuke/github-api 2017-09-08 15:52:31 -07:00
Kohsuke Kawaguchi
8dd6dbf995 getRef never returns null 2017-09-08 15:52:11 -07:00
Kohsuke Kawaguchi
612139f2ff Merge pull request #375 from stephenc/tag-object-support
Add basic support for tag objects
2017-09-08 15:49:33 -07:00
Kohsuke Kawaguchi
240bcabb76 Merge pull request #351 2017-09-08 14:16:45 -07:00
Kohsuke Kawaguchi
cda27d5963 This field should be still final 2017-09-08 14:16:09 -07:00
Kohsuke Kawaguchi
2f8c3997f7 Restored signature of the previous enableProtection() method 2017-09-08 14:13:21 -07:00
Kohsuke Kawaguchi
46b89a48db Merge Pull request #369 2017-09-08 14:06:22 -07:00
Kohsuke Kawaguchi
5c9cbee2f9 Merge pull request #332 from sebkur/fix_javadoc
Fix a bug in the Javadocs (due to copy and paste)
2017-09-08 10:39:58 -07:00
Kohsuke Kawaguchi
ee8973c239 Merge pull request #338 from sebkur/ignore-eclipse-files
Ignore eclipse files
2017-09-08 10:39:39 -07:00
Kohsuke Kawaguchi
2e2813f363 Merge pull request #343 from kamontat/feature/latest-release
add latest release
2017-09-08 10:39:13 -07:00
Kohsuke Kawaguchi
7ceca0769f Merge pull request #363 from PauloMigAlmeida/master
Add missing event types used by repository webhooks
2017-09-08 10:36:33 -07:00
Kohsuke Kawaguchi
4d277cc61f Merge pull request #352 from stephenc/pr-reviews
Add support for PR reviews preview
2017-09-08 10:35:58 -07:00
Kohsuke Kawaguchi
e67fbb4621 Merge pull request #362 from KostyaSha/pingHook
Add ping hook method
2017-09-08 10:34:45 -07:00
Kohsuke Kawaguchi
29b5357ceb Merge pull request #358 from jglick/no-preview-JENKINS-36240
[JENKINS-36240] /repos/:owner/:repo/collaborators/:username/permission no longer requires korra preview
2017-09-08 10:33:31 -07:00
Stephen Connolly
9dabec107b Add basic support for tag objects 2017-09-01 12:52:15 +01:00
Matt Mitchell
f2a2ad90b7 Switch to a concurrent hash map 2017-08-29 11:30:25 -07:00
Matt Mitchell
cfe4c0c510 Merge remote-tracking branch 'upstream/master' into synchro-api 2017-08-29 10:38:54 -07:00
Jae Gangemi
23cd51a6da - improved branch protection support 2017-08-08 16:17:58 -06:00
Jae Gangemi
7396395f90 - updated ignore entries for eclipse/moc os 2017-08-08 14:31:11 -06:00
adw1n
a1819bf232 Added getClones method to GHRepository (https://developer.github.com/v3/repos/traffic/#clones). 2017-08-01 06:38:28 +02:00
adw1n
8accf07d46 Changed timestamp (GHRepositoryViews.DayViews.timestamp) field type from String to Date. 2017-08-01 04:02:10 +02:00
adw1n
6dcbace572 Added getViews method to GHRepository.
getViews implements https://developer.github.com/v3/repos/traffic/#views
2017-08-01 03:38:46 +02:00
Greg Gianforcaro
e90c86ec2f Remove Preview status, merge_method is now out of preview 2017-07-18 11:36:38 -04:00
Greg Gianforcaro
971ae1fa4d Merge branch 'master' into pr-merge-method 2017-07-18 11:33:20 -04:00
Paulo Miguel Almeida
4abe87036c Add missing event types used by repository webhooks 2017-07-14 04:23:08 +00:00
Kanstantsin Shautsou
8d1b44db97 Add ping hook method 2017-07-10 02:39:03 +03:00
Serban Iordache
b537f9925b issue #360: Add support for committing multiple files 2017-07-07 16:21:11 +02:00
Kohsuke Kawaguchi
f2fe8eaf86 [maven-release-plugin] prepare for next development iteration 2017-07-02 17:08:35 -07:00
Kohsuke Kawaguchi
46715cac08 [maven-release-plugin] prepare release github-api-1.86 2017-07-02 17:08:24 -07:00
Kohsuke Kawaguchi
0f21eba57f Merge pull request #359 from jglick/SocketTimeoutException-JENKINS-45142
[JENKINS-45142] Retry connections after getting SocketTimeoutException
2017-06-29 17:13:31 -04:00
Jesse Glick
cb7620395a [JENKINS-45142] Retry connections after getting SocketTimeoutException. 2017-06-28 17:09:54 -04:00
Jesse Glick
3a40af8871 [JENKINS-36240] /repos/:owner/:repo/collaborators/:username/permission no longer requires korra preview. 2017-06-12 10:28:25 -04:00
mdeverdelhan
c9b5074bc4 Fix the wrapping of retrieved commits (owner/repository) 2017-05-11 12:32:34 +02:00
Stephen Connolly
44d4d0d767 Add support for PR reviews preview 2017-03-30 12:17:06 +01:00
mdeverdelhan
64af13f40d Add the Commit search API (still in preview) 2017-03-30 12:55:55 +02:00
Kohsuke Kawaguchi
e9b59c6bef [maven-release-plugin] prepare for next development iteration 2017-02-28 21:06:14 -08:00
Kohsuke Kawaguchi
3d03659508 [maven-release-plugin] prepare release github-api-1.85 2017-02-28 21:06:08 -08:00
Kohsuke Kawaguchi
0374d2de48 Merge pull request #346 from stephenc/close-the-connections
Ensure that connections are closed for error responses
2017-02-27 12:33:18 -08:00
Stephen Connolly
2627dc5ee4 Ensure that connections are closed for error responses
- This was endless fun to trace, but I found it at last. This should
stop the `WARNING: A connection to https://api.github.com/ was leaked.
Did you forget to close a response body?` messages in the logs when
using the OkHttpConnector.
2017-02-23 12:52:29 +00:00
kamontat
5554332b5b add return null if latest release not found 2017-02-20 10:20:53 +07:00
kamontat
1cffea892b add test 2017-02-20 10:20:08 +07:00
kamontat
fd859815b0 fixed indent, rename to getLastestRelease 2017-02-20 09:36:28 +07:00
kamontat
166e26d101 add latest release 2017-02-19 23:57:44 +07:00
Kanstantsin Shautsou
be081eec3f Inject responce headers in GHObject and Exceptions.
GH has specific to GET/POST headers required for analysing in case of error.

Signed-off-by: Kanstantsin Shautsou <kanstantsin.sha@gmail.com>
2017-02-10 04:11:20 +03:00
Kanstantsin Shautsou
55b00a87f6 Set 1.6 level. I'm not so old.
Signed-off-by: Kanstantsin Shautsou <kanstantsin.sha@gmail.com>
2017-02-10 03:28:06 +03:00
Sebastian Kürten
429b26cee8 Ignore eclipse files 2017-02-09 18:18:08 +01:00
Sebastian Kürten
fafe6b0ff7 Remove unused imports
Especially also remove the unsued import of
javax.xml.bind.DatatypeConverter from GHContent which is non-public API
as of Java 8
2017-02-09 18:15:20 +01:00
Greg Gianforcaro
5b156006fb Add 'Preview' support for MergeMethod on GHPullRequest
- Add 'polaris' preview
- Add MergeMethod Enum
- Add merge method to GHPullRequest which takes a MergeMethod
2017-01-27 23:36:54 -05:00
Sebastian Kürten
75f0c08ca4 Fix a bug in the Javadocs (due to copy and paste) 2017-01-23 12:21:13 +01:00
Kohsuke Kawaguchi
1f4325e7db Merge pull request #329 from stephenc/patch-1
Correct algebra in #327
2017-01-16 18:31:33 -08:00
Stephen Connolly
f2e7b40425 Correct algebra in #327 2017-01-10 10:15:04 +00:00
Kohsuke Kawaguchi
4ee3086b6d [maven-release-plugin] prepare for next development iteration 2017-01-09 16:50:15 -08:00
Kohsuke Kawaguchi
a3a715c3ba [maven-release-plugin] prepare release github-api-1.84 2017-01-09 16:50:08 -08:00
Kohsuke Kawaguchi
6cad4a3c33 static import for conciseness 2017-01-09 16:43:03 -08:00
Kohsuke Kawaguchi
b9b6f4fd44 INFO level logging is harmful as it's reported to stdout by default 2017-01-09 16:42:03 -08:00
Kohsuke Kawaguchi
17d1994a53 [maven-release-plugin] prepare for next development iteration 2017-01-09 16:38:02 -08:00
Kohsuke Kawaguchi
13184e72e1 [maven-release-plugin] prepare release github-api-1.83 2017-01-09 16:37:56 -08:00
Kohsuke Kawaguchi
911e8d21a7 Made the test case runnable, at least for me 2017-01-09 16:26:58 -08:00
Kohsuke Kawaguchi
5b69a2925f Merge pull request #324 2017-01-09 16:18:48 -08:00
Kohsuke Kawaguchi
d1c900a620 Marking the fact that these APIs are still in preview and subject to change 2017-01-09 16:18:40 -08:00
Kohsuke Kawaguchi
6bfeb54f3c Just exposing permission type enum until there's more to this relation than one property 2017-01-09 16:14:30 -08:00
Kohsuke Kawaguchi
198fede915 Merge pull request #325 2017-01-09 16:06:14 -08:00
Kohsuke Kawaguchi
1212ae3eb3 Touch up for uniformity
- Prefer typed 'URL' over 'String' that is URL
- Mark API as @Preview to communicate that this is subject to change

More branch protection stuff needs to be added. See https://developer.github.com/v3/repos/branches/
2017-01-09 16:06:05 -08:00
Kohsuke Kawaguchi
1266dcc0c7 Merge pull request #327 from stephenc/expose-rate-limit-headers
Expose Rate Limit Headers
2017-01-10 08:57:07 +09:00
Stephen Connolly
6fcddf4a47 Some usage patterns require more pro-active rate limit queries 2017-01-05 10:25:40 +00:00
Stephen Connolly
dfea424b94 Expose the API url used by the GitHub 2017-01-05 09:36:58 +00:00
Stephen Connolly
9d03435aa1 Expose Rate Limit Headers
Exposes the rate limit header responses so that consumers of the API can proactively tune their usage
2017-01-05 09:21:32 +00:00
Jeffrey.Nelson
26c20a7a22 add branch protection attributes 2016-12-22 11:55:01 -06:00
Kohsuke Kawaguchi
470da06ecf Cleaning up javadoc warnings 2016-12-17 08:17:20 -08:00
Kohsuke Kawaguchi
a746a310bc [maven-release-plugin] prepare for next development iteration 2016-12-17 07:50:55 -08:00
Kohsuke Kawaguchi
3dbb516084 [maven-release-plugin] prepare release github-api-1.82 2016-12-17 07:50:48 -08:00
Kohsuke Kawaguchi
32177283b3 Fixed issue #317
There's no need for the library to replicate a logic when GitHub does
that (and does that correctly.)

Looking at the commit history, I couldn't see why this was added in the
first place.
2016-12-17 07:30:14 -08:00
Kohsuke Kawaguchi
3a66e90b7a Fixed issue #319
getApiUrl() is unreliable given that we collapse issue & PR into one
object.
2016-12-17 07:28:28 -08:00
Kohsuke Kawaguchi
a454fb10ec Tree traversal from commit & its associated tests 2016-12-17 07:21:31 -08:00
Kohsuke Kawaguchi
b5386a35ee Defining better traversal methods for apps that walk trees 2016-12-17 07:09:29 -08:00
Kohsuke Kawaguchi
11651da411 not always a blob, for example it could be a tree. 2016-12-17 07:04:31 -08:00
Kohsuke Kawaguchi
88d52c44ad Recording parent GHRepository 2016-12-17 07:03:40 -08:00
Kohsuke Kawaguchi
2d7d4bbd4e Merge pull request #320 with some additional changes 2016-12-17 06:56:41 -08:00
Kohsuke Kawaguchi
e6ee278fde Another version that directly reads BLOB without going through an intermediate object. 2016-12-17 06:55:44 -08:00
Kohsuke Kawaguchi
6380cf9ed0 Added a method to retrieve the actual bytes of BLOB
... which is probably more useful than the getContent() method
2016-12-17 06:47:24 -08:00
Kohsuke Kawaguchi
2e78dc52c7 Merge pull request #323 from jglick/bad-json
Fix syntactically malformed test JSON
2016-12-17 06:24:43 -08:00
Jesse Glick
ccb42d3249 [JENKINS-36240] Added GHRepository.getPermission(String). 2016-12-16 18:02:28 -05:00
Jesse Glick
c5009ab44b Fix syntactically malformed test JSON. 2016-12-16 15:04:10 -05:00
Jeff Nelson
9d15cd43a3 Merge pull request #1 from kohsuke/master
catchup
2016-12-14 12:12:57 -06:00
Kanstantsin Shautsou
0780e10fa2 Added ghRepo.getBlob(String) method
Signed-off-by: Kanstantsin Shautsou <kanstantsin.sha@gmail.com>
2016-12-13 15:28:08 +03:00
Kohsuke Kawaguchi
0731f63237 Added order parameter 2016-11-26 14:45:03 -08:00
Kohsuke Kawaguchi
a29896042b Merge pull request #315 from davidxia/dxia/patch1
Fix typos in javadocs
2016-11-26 14:38:45 -08:00
David Xia
68ebc08c9d Fix typos in javadocs
Replace "pagenated" with "paginated".
2016-11-26 00:44:52 -05:00
Kohsuke Kawaguchi
a1df526f93 [maven-release-plugin] prepare for next development iteration 2016-11-21 08:53:42 -08:00
Kohsuke Kawaguchi
0023ecefa4 [maven-release-plugin] prepare release github-api-1.81 2016-11-21 08:53:38 -08:00
Kohsuke Kawaguchi
511f156603 Added the membership API for the authenticated user. 2016-11-19 15:26:04 -08:00
Kohsuke Kawaguchi
3f223b1ba0 Support assignees when creating a new issue 2016-11-19 14:50:47 -08:00
Kohsuke Kawaguchi
a1528a1a63 API to add/set/remove assignees from an issue 2016-11-19 14:48:43 -08:00
Kohsuke Kawaguchi
b8bfddbf3a Code simplification 2016-11-19 14:30:35 -08:00
Kohsuke Kawaguchi
47fc813027 Assignees of the repository.
(Personally this concept makes no sense for me, so I don't know what this API really does. I'm just following their API docs)
2016-11-19 14:29:27 -08:00
Kohsuke Kawaguchi
c7f2228a44 [maven-release-plugin] prepare for next development iteration 2016-11-16 22:52:14 -08:00
Kohsuke Kawaguchi
b0e0f045f8 [maven-release-plugin] prepare release github-api-1.80 2016-11-16 22:52:10 -08:00
Kohsuke Kawaguchi
1296514794 this field is not yet used 2016-11-16 22:49:13 -08:00
Kohsuke Kawaguchi
18e797095f rewrote assert with JUnit ones 2016-11-16 22:36:16 -08:00
Kohsuke Kawaguchi
85aa2ad4e6 Added reaction API 2016-11-16 19:10:37 -08:00
Kohsuke Kawaguchi
818f6dc045 Issue #309: Added user listing 2016-11-16 18:26:49 -08:00
Kohsuke Kawaguchi
1c162c6390 Merge pull request #304 2016-11-16 18:19:26 -08:00
Kohsuke Kawaguchi
def3a28fb5 Restoring backward compatibility of names 2016-11-16 18:18:45 -08:00
Kohsuke Kawaguchi
d1378a0236 Merge pull request #306 from stephenc/offline-support
Add offline support to the API to make parsing events easier
2016-11-16 18:12:39 -08:00
Stephen Connolly
e544c7a65a Fix the push event payload 2016-11-14 12:52:22 +00:00
Kanstantsin Shautsou
24f48f668c Add portion of auth/application API. (#307)
* Add portion of auth/application API.

Signed-off-by: Kanstantsin Shautsou <kanstantsin.sha@gmail.com>

* fixup
2016-11-11 15:56:03 +01:00
Stephen Connolly
9988a090ac Add some more tests 2016-11-11 14:27:09 +00:00
Stephen Connolly
d36e145d06 Need to be able to tell if this is a creation / deletion of a ref for multibranch projects 2016-11-11 14:18:47 +00:00
Stephen Connolly
498d63ea00 Typos spotted by Jesse 2016-11-08 15:48:39 +00:00
Stephen Connolly
7dc620a3ba More details emerge on the PingEvent payload 2016-11-08 15:29:27 +00:00
Stephen Connolly
66145e1d23 Seems there is an undocumented but important PING event used by github-plugin 2016-11-08 15:26:33 +00:00
Stephen Connolly
7bf8621afe Need the pusher details for github-plugin 2016-11-08 15:14:42 +00:00
Stephen Connolly
ce3f74232e Ensure a use case required by github-plugin is valid 2016-11-08 15:11:35 +00:00
Stephen Connolly
5b92d4b88c Fix findbugs false alarms 2016-11-08 15:04:02 +00:00
Stephen Connolly
4daf6ba057 Add offline support to the API to make parsing events easier
- When we receive events from a webhook, it is non-trivial to determine which GitHub instance the event came from
  or for that matter even if the event actually came from GitHub or GitHub Enterprise.
- In order to ensure that the logic for parsing events does not get replicated in clients, we need to be
  able to call GitHub.parseEventPayload(Reader,Class) without knowing which GitHub the event originates from
  and without the resulting objects triggering API calls back to a GitHub
- Thus we add GitHub.offline() to provide an off-line connection
- Thus we modify some of the object classes to return best-effort objects when off-line
- Add support for more of the event types into GHEventPayload
- Add tests of the event payload and accessing critical fields when using GitHub.offline()
2016-11-08 12:56:52 +00:00
Jason Song
955e9899af Fix fields of GHRepository 2016-11-04 00:09:59 +08:00
Kohsuke Kawaguchi
fa3d0887ef [maven-release-plugin] prepare for next development iteration 2016-10-24 19:23:18 -07:00
Kohsuke Kawaguchi
5d5c6cf71c [maven-release-plugin] prepare release github-api-1.79 2016-10-24 19:23:14 -07:00
Kohsuke Kawaguchi
89aac45f41 Merge pull request #299 2016-10-24 19:15:46 -07:00
Kohsuke Kawaguchi
4965fd5f4c Noting possible TODO for the future 2016-10-24 19:15:38 -07:00
Kohsuke Kawaguchi
87fbb8ec98 Copy/paste error 2016-10-24 19:07:32 -07:00
Kohsuke Kawaguchi
0d92d4ba61 [maven-release-plugin] prepare for next development iteration 2016-10-24 14:10:35 -07:00
Kohsuke Kawaguchi
b0df93bbcb [maven-release-plugin] prepare release github-api-1.78 2016-10-24 14:10:30 -07:00
Kohsuke Kawaguchi
290d0b226a Merge pull request #295 from jglick/pageSize
Use maximum permitted page size
2016-10-24 14:04:05 -07:00
Kohsuke Kawaguchi
8b3469610c Merge pull request #300 from stephenc/commit-dates
Expose the commit dates
2016-10-24 14:03:14 -07:00
Stephen Connolly
50b47fb73b Expose the commit dates 2016-10-24 21:12:56 +01:00
Ben Sheats
5334cb8688 url encode hashes in ref names 2016-10-21 11:40:01 -04:00
Jesse Glick
38983df42d If we are a returning a collection of all things, we might as well use the maximum page size to minimize HTTP requests. 2016-09-19 09:48:23 -07:00
Kohsuke Kawaguchi
df963cb71c [maven-release-plugin] prepare for next development iteration 2016-08-05 21:32:15 -07:00
Kohsuke Kawaguchi
e9368fb04e [maven-release-plugin] prepare release github-api-1.77 2016-08-05 21:32:10 -07:00
Kohsuke Kawaguchi
e2a1630cf4 findbug taming 2016-08-05 21:28:54 -07:00
Kohsuke Kawaguchi
4f15b7c9fa NPE fix. type can be null 2016-08-05 21:19:32 -07:00
Kohsuke Kawaguchi
63f500ad7f Fixed issue #286
List commit API (https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository) already populates short info, and so populate() call could be excessive.

 It's possible that the short info is always available and therefore there's never a need to call populate(), but that assumption is hard to test, so I'm leaving that in
2016-08-05 21:11:00 -07:00
Kohsuke Kawaguchi
a9fb4546e1 Constants for preview media types 2016-08-05 20:56:11 -07:00
Kohsuke Kawaguchi
cabbbf7f02 Handle 404 that represents "no license" 2016-08-05 20:50:39 -07:00
Kohsuke Kawaguchi
59324b0082 Add preview media type header explicitly 2016-08-05 20:47:08 -07:00
Kohsuke Kawaguchi
6a356c82a5 Fixed up tests 2016-08-05 20:44:45 -07:00
Kohsuke Kawaguchi
70f0f5714a While a use of custom HttpConnector is clever, it doesn't fit the current idiom of this library. 2016-08-05 20:44:10 -07:00
Kohsuke Kawaguchi
07b527a0f2 Enumeration in GitHub should be PagedIterable 2016-08-05 20:40:34 -07:00
Kohsuke Kawaguchi
80aa75aab1 Added the wrap() method for a backpointer 2016-08-05 20:40:23 -07:00
Kohsuke Kawaguchi
0cf4211aa5 Merged GHLicense & GHLicenseBase
Elsewhere in this library, whenever there are multiple forms of the same
object, we map that to the same class and use lazy data retrieval to
fill missing fields.
2016-08-05 20:36:46 -07:00
Kohsuke Kawaguchi
1de02a5099 Added a marker for preview APIs 2016-08-05 20:19:36 -07:00
Duncan Dickinson
bb1cecb95b PR-284: license API support
Had to do git-diff | git-apply to avoid whitespe changes to GHRepository
2016-08-05 20:11:33 -07:00
Kohsuke Kawaguchi
d82397a173 doc fix 2016-08-05 20:00:05 -07:00
Kohsuke Kawaguchi
856cf5e568 Better type safety by splitting RateLimitHandler and AbuseLimitHandler
While the signature is the same, headers that they expect are different,
so any non-trivial logic cannot be reused.
2016-08-05 19:58:04 -07:00
Matt Mitchell
9f5a6ee549 Implement an abuse handler
If too many requests are made within X amount of time (not the traditional hourly rate limit), github may begin returning 403.  Then we should wait for a bit to attempt to access the API again.  In this case, we parse out the Retry-After field returned and sleep until that (it's usually 60 seconds)
2016-07-22 13:16:12 -07:00
Matt Mitchell
9f3f644b83 Add some level of synchronization to the root of the API
This adds some synchronization to the maps at the root of the API to avoid duplicated calls to the actual GH REST API.  Specifically this is targeted around the two maps, orgs and users.  This fix makes the GHPRB jenkins plugin behave much better when there are lots of projects that could build for a specific repo (even if only a few are actually triggered)

There are also a few fixes around GHUser and GHPullRequest
* GHPullRequest was checking a field that may be null (merged_by) when determining whether to fetch details.  An unmerged PR would make a bunch of Github API calls for each property accessed.
* Where GHUser was returned in various objects, we weren't going through the caching mechanism at the root, so calls to APIs on GHUSer often resulted in new REST calls.  Instead, return from the cache wherever possible.
2016-06-08 10:43:40 -07:00
Kohsuke Kawaguchi
a2f0837d14 Issue #279: added another overload that takes permission 2016-06-03 20:56:17 -07:00
Kohsuke Kawaguchi
c7f6889534 Issue #258: updated OkHttp that handles Cache control headers better 2016-06-03 20:31:12 -07:00
Kohsuke Kawaguchi
0415326d09 Issue #261: handle 204 no content correctly 2016-06-03 20:27:29 -07:00
Kohsuke Kawaguchi
16a0f8ece0 [maven-release-plugin] prepare for next development iteration 2016-06-03 00:19:15 -07:00
Kohsuke Kawaguchi
5d1ef296b3 [maven-release-plugin] prepare release github-api-1.76 2016-06-03 00:19:09 -07:00
Kohsuke Kawaguchi
16dbcde90b Shut up FindBugs! 2016-06-03 00:16:20 -07:00
Kohsuke Kawaguchi
50cbf25c72 Shut up FindBugs 2016-06-03 00:09:25 -07:00
Kohsuke Kawaguchi
7b87de2b4c Giving it a bit of delay in the hope that it removes flakiness of tests 2016-06-03 00:04:36 -07:00
Kohsuke Kawaguchi
1ce54a7925 Bug fix in toString() 2016-06-02 23:55:55 -07:00
Kohsuke Kawaguchi
1bfe7dd99b Issue #264: wait for the repo to finish forking 2016-06-02 23:50:18 -07:00
Kohsuke Kawaguchi
27e855ddbd Issue 262: added support for branch protection API 2016-06-02 23:40:37 -07:00
Kohsuke Kawaguchi
3d1bed0f8f In JDK I'm using (Java8), I get a delegating HttpURLConnection that breaks the hack to set the method.
This change makes this hack even worse, but this is the only way I can think of, since I cannot update HttpURLConnection.methods that is static final.
2016-06-02 23:40:14 -07:00
Kohsuke Kawaguchi
5c9ea9b63a Added a fluent version 2016-06-02 23:27:52 -07:00
Kohsuke Kawaguchi
7c034f5670 Doc improvement 2016-06-02 22:43:58 -07:00
Kohsuke Kawaguchi
3b9f5a417a Formatting changes 2016-06-02 22:43:06 -07:00
Kohsuke Kawaguchi
cde501af8d More meaningful toString() method
Produce toString without dilligently adding it to every single class.
Rely on heuristics to cut down the number of fields to show.
2016-06-02 22:38:38 -07:00
Kohsuke Kawaguchi
3c5592c1c8 Following the convention with GHMyself.getEmails2()
This way the method is more discoverable with IDE auto-completion
2016-06-02 22:05:24 -07:00
Kohsuke Kawaguchi
2508e022bb Merge pull request #272 from noctarius/master
Added support for the extended stargazers API in Github V3 API
2016-06-03 14:04:24 +09:00
Kohsuke Kawaguchi
01fcbc24e8 Merge pull request #282 from apemberton/org-fix
related to JENKINS-34834. updating test for similar condition
2016-06-03 13:52:26 +09:00
Kohsuke Kawaguchi
204e639679 Merge pull request #281 from apemberton/master
Add Slug to GHTeam per v3 API: https://developer.github.com/v3/orgs/t…
2016-06-03 13:51:47 +09:00
Kohsuke Kawaguchi
3d301ec730 Merge pull request #278 from jglick/javadoc
Fixed broken link
2016-06-03 13:50:37 +09:00
Kohsuke Kawaguchi
9ab6d57019 Merge pull request #277 from rhels/patch-1
Updated Date was wrong
2016-06-03 13:50:22 +09:00
Kohsuke Kawaguchi
37c473130f Merge pull request #276 from thug-gamer/patch-1
Add support to delete a team
2016-06-03 13:50:11 +09:00
Andy Pemberton
5f95987a48 related to JENKINS-34834. updating test for similar condition 2016-05-14 20:07:04 -04:00
Andy Pemberton
d530b34073 Add Slug to GHTeam per v3 API: https://developer.github.com/v3/orgs/teams/ 2016-05-14 08:58:42 -04:00
Jesse Glick
35dec7a5ec Fixed broken link. 2016-05-03 18:19:57 -04:00
Konda Reddy
baedad8124 Updated Date was wrong 2016-04-30 13:20:44 -05:00
thug-gamer
007378c3a6 Add support to delete a team
Add a method to delete a team.
2016-04-29 11:41:14 +02:00
noctarius
beae9fd6ec Added support for the extended stargazers API in Github V3 API 2016-04-14 07:22:17 +02:00
Kohsuke Kawaguchi
b7507076c6 Merge pull request #270 from szpak/issue/269-reopenMilestone
[#269] Add reopen method on GHMilestone
2016-04-13 16:15:39 -07:00
Kohsuke Kawaguchi
6b5ade3ca0 [maven-release-plugin] prepare for next development iteration 2016-04-13 13:08:02 -07:00
Kohsuke Kawaguchi
715192d26c [maven-release-plugin] prepare release github-api-1.75 2016-04-13 13:07:58 -07:00
Marcin Zajaczkowski
ce140460af [#269] Add reopen method on GHMilestone 2016-04-04 17:54:55 +02:00
Kohsuke Kawaguchi
d30b0403ce [maven-release-plugin] prepare for next development iteration 2016-03-18 19:22:37 -07:00
Kohsuke Kawaguchi
255c993548 [maven-release-plugin] prepare release github-api-1.74 2016-03-18 19:22:34 -07:00
Kohsuke Kawaguchi
557ae4165c Not important 2016-03-18 19:19:51 -07:00
Kohsuke Kawaguchi
a31395ed80 Signature fix for Java5 2016-03-18 19:15:52 -07:00
Kohsuke Kawaguchi
397886d289 Excluding a flaky test 2016-03-18 19:08:51 -07:00
Kohsuke Kawaguchi
7307bec2ae Merge pull request #259 from Shredder121/animal-sniffer
Animal sniffer
2016-03-18 18:27:22 -07:00
Ruben Dijkstra
0cd5147e1a Java 5 doesn't have TimeUnit.HOURS
http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/TimeUnit.html
2016-03-12 22:01:25 +01:00
Ruben Dijkstra
36d5b092d7 Java 5 doesn't have new String(byte[], Charset)
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html
2016-03-12 21:59:51 +01:00
Ruben Dijkstra
f9014dbab3 Convert to legacy Throwable.initCause() 2016-03-12 21:58:27 +01:00
Ruben Dijkstra
755d5f77ea Java 5 doesn't have Arrays.copyOf()
http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Arrays.html
2016-03-12 21:56:56 +01:00
Ruben Dijkstra
906d9af7b7 Include the animal sniffer plugin
7a78f9f5aa set the compiler level back to 5, but there are no guarantees that we don't accidentally use any features from newer class libraries.
2016-03-12 21:48:50 +01:00
Kohsuke Kawaguchi
14dcb37ee1 Not all caller wants GET 2016-03-11 23:29:58 -08:00
Kohsuke Kawaguchi
c1c2a27358 Doc improvement 2016-03-11 23:21:07 -08:00
Kohsuke Kawaguchi
5ab9657f9c Merge branch 'master' of github.com:kohsuke/github-api 2016-03-11 23:16:37 -08:00
Kohsuke Kawaguchi
7a78f9f5aa No need to require 1.6 2016-03-11 23:16:24 -08:00
Kohsuke Kawaguchi
ac8c65f062 Merge pull request #251
Conflicts:
	src/main/java/org/kohsuke/github/GitHub.java
2016-03-11 23:14:01 -08:00
Kohsuke Kawaguchi
1954a9f3f8 This isn't just about API URL but it also checks the valid credential 2016-03-11 23:12:50 -08:00
Kohsuke Kawaguchi
3b764f9c90 Don't lose the original problem 2016-03-11 23:11:22 -08:00
Kohsuke Kawaguchi
10f55cc549 Checking another header
I think it's better to pick a header that's unique to GitHub.
2016-03-11 23:10:41 -08:00
Kohsuke Kawaguchi
cd8d955646 Documenting what one gets 2016-03-11 23:06:21 -08:00
Kohsuke Kawaguchi
bba07c9080 Merge pull request #253 from cyrille-leclerc/fix-infinite-loop
Fix #252: infinite loop because the "hypertext engine" generates invalid URLs
2016-03-11 22:59:00 -08:00
Kohsuke Kawaguchi
dba84a33b9 Logger should be static 2016-03-11 22:55:58 -08:00
Kohsuke Kawaguchi
ae49166aa2 No such parameter exists on this method 2016-03-11 22:55:44 -08:00
Kohsuke Kawaguchi
e09185fd0e Logger should be static 2016-03-11 22:51:48 -08:00
Cyrille Le Clerc
56379bb3b9 Fix broken log message in GitHub.java and cleanup code as recommended by @jglick 2016-03-07 19:25:42 +01:00
Cyrille Le Clerc
027e4b4f25 Better error message: introduce HttpException, subclass of IOException with url, http responseCode and http responseMessage to help exception handling. 2016-03-06 18:34:27 +01:00
Cyrille Le Clerc
ba951cb6e3 Fix #252: infinite loop because the "hypertext engine" may duplicate '?' generating invalid "https://api.github.com/notifications?all=true&page=2?all=true" instead of "https://api.github.com/notifications?all=true&page=2&all=true". A better fix will be to prevent duplication of parameters ("all=true" in this case). 2016-03-06 18:27:05 +01:00
Manuel Recena
ae85cf4b6c Improve checkApiUrlValidity() method to support the private mode in GitHub Enterprise servers 2016-03-05 17:42:25 +01:00
Kohsuke Kawaguchi
dbc79f8c42 Fixing issue raised in https://github.com/kohsuke/github-api/pull/247
From Shredder121,
--------------------
Only the HttpURLConnection.method was set by that change. Not the
Requester.method.

This means that Requester.method is still set to POST, isMethodWithBody
will return true, and uc.setDoOutput(true) will be called.

I use Okhttp, and their HttpURLConnectionImpl's method changes to POST
if you tell it to open a stream to write to.
2016-03-01 19:46:50 -08:00
Kohsuke Kawaguchi
54c3070607 [maven-release-plugin] prepare for next development iteration 2016-02-29 21:03:34 -08:00
Kohsuke Kawaguchi
013eaa30b6 [maven-release-plugin] prepare release github-api-1.73 2016-02-29 21:03:31 -08:00
Kohsuke Kawaguchi
751043bf81 change in the markup generated 2016-02-29 21:01:18 -08:00
Kohsuke Kawaguchi
14f7198a07 Handle "all" webhook correctly
This fixes #250
2016-02-29 20:56:47 -08:00
Kohsuke Kawaguchi
94af819ae5 Merge pull request #249 from zapelin/master
Added getHtmlUrl() to GHCommit
2016-02-29 20:48:19 -08:00
Kohsuke Kawaguchi
dbcc9afbc7 Merge pull request #248 from daniel-beck/populate-commit
Populate commit with data for getCommitShortInfo
2016-02-29 20:47:52 -08:00
Kohsuke Kawaguchi
8556033ae6 Merge pull request #245 from daniel-beck/email-hook-error
Fix error when creating email service hook
2016-02-29 20:45:40 -08:00
Kohsuke Kawaguchi
650493f863 Merge pull request #244 from benbek/patch-1
Minor amendment to the documentation
2016-02-29 19:57:47 -08:00
Kohsuke Kawaguchi
d80ad77871 Use builder pattern to support all the other options 2016-02-29 19:57:16 -08:00
Artem Gubanov
f4b129b9f1 Added getHtmlUrl() to GHCommit 2016-02-25 10:46:17 +02:00
Daniel Beck
c0a05e0650 Populate commit with data for getCommitShortInfo 2016-02-21 01:26:43 +01:00
Daniel Beck
33d95d3e3a Fix error when creating email service hook 2016-01-20 23:30:10 +01:00
benbek
f573f83fb9 Amendment to the documentation
The status reported by GitHub for deleting a file is actually "removed", not "deleted".
2016-01-19 00:05:01 +02:00
Daniel Lovera
e94c36b7e6 clean: remove unused import 2015-12-13 21:05:36 +01:00
Daniel Lovera
c879e9e34d Support for auto_init parameter in organization
The GitHub api auto_init parameter allows to initialize created repository with a readme file.
Add createRepository methods in GHOrganization using auto_init parameter. Already existing createRepository methods use auto_init parameter as false for retro-compatibility.
2015-12-13 21:00:40 +01:00
Daniel Lovera
ac39b564a8 Support for auto_init parameter
The GitHub api auto_init parameter allows to initialize created repository with a readme file.
Add a createRepository method using auto_init parameter. Already existing createRepository method uses auto_init parameter as false for retro-compatibility.
2015-12-13 20:59:49 +01:00
Kohsuke Kawaguchi
d91388aba4 [maven-release-plugin] prepare for next development iteration 2015-12-10 07:00:06 -08:00
Kohsuke Kawaguchi
733d78abdd [maven-release-plugin] prepare release github-api-1.72 2015-12-10 06:59:37 -08:00
Kohsuke Kawaguchi
d5809e375c Simplification via enum handling in 'req.with' 2015-12-10 06:33:49 -08:00
Kohsuke Kawaguchi
2440a676bd Added more comprehensive API to list pull requests
This fixes issue #234
2015-12-10 06:26:04 -08:00
Kohsuke Kawaguchi
03ac6c72e7 Formatting change 2015-12-10 06:01:34 -08:00
Kohsuke Kawaguchi
1bbbcabae0 Making API flow better 2015-12-10 05:56:08 -08:00
Kohsuke Kawaguchi
9149b6b998 GHCommit might be only partially populated.
This fixes issue #230
2015-12-10 05:53:55 -08:00
Kohsuke Kawaguchi
2603b5a402 Added stargazers and stars 2015-12-03 17:55:06 +01:00
Kohsuke Kawaguchi
dbddf5b9eb Implemented pagenation size support. 2015-12-03 17:41:43 +01:00
Kohsuke Kawaguchi
841f77bac2 Naming anonymous iterator.
... in anticipation of the page size support.
2015-12-03 16:33:39 +01:00
Kohsuke Kawaguchi
83ffe75baa Fixed rate handling limit handling
Issue #220. If RateLimitHandler returns normally, it should retry.
2015-12-02 12:03:39 +01:00
Kohsuke Kawaguchi
8cb7094803 Added pagination for following & follower 2015-12-02 08:35:56 +01:00
Kohsuke Kawaguchi
ed8cd0ad19 Added getter for ID
And the actual value has already gone past 'int'

This fixes issue #199
2015-12-01 17:02:53 +01:00
Kohsuke Kawaguchi
90d8e65a3b [maven-release-plugin] prepare for next development iteration 2015-12-01 16:27:29 +01:00
2087 changed files with 968807 additions and 1655 deletions

19
.github/release-drafter.yml vendored Normal file
View File

@@ -0,0 +1,19 @@
name-template: 'v$NEXT_PATCH_VERSION 🌈'
tag-template: 'v$NEXT_PATCH_VERSION'
categories:
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: '🧰 Maintenance'
label: 'chore'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
template: |
## Changes
$CHANGES

22
.github/workflows/maven-build.yml vendored Normal file
View File

@@ -0,0 +1,22 @@
name: Java CI Build and Test
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '1.8.0', '11.0.x', '13.0.x' ]
steps:
- uses: actions/checkout@v1
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Maven Download all dependencies
run: mvn -B org.apache.maven.plugins:maven-dependency-plugin:3.1.1:go-offline
- name: Maven Build
run: mvn -B install site --file pom.xml

4
.gitignore vendored
View File

@@ -3,3 +3,7 @@ target
*.iml
*.ipr
*.iws
.classpath
.project
.settings/
.DS_Store

76
CODE_OF_CONDUCT.md Normal file
View File

@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at bitwiseman@gmail.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

62
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,62 @@
# Contributing
## Using WireMock and Snapshots
This project has started converting to using WireMock to stub out http responses instead of use live data.
This change will allow tests to run in a CI environment without needing to touch github.com.
The tests will instead serve previously recorded responses from local data files.
### Running WireMock tests
Example:
`mvn install -Dtest=WireMockStatusReporterTest`
This the default behavior.
### Setting up credential
1. Create an OAuth token on github.com
2. Set the GITHUB_OAUTH environment variable to the value of that token
3. Set the system property `test.github.useProxy` (usually like "-Dtest.github.useProxy" as a Java VM option)
`mvn install -Dtest.github.useProxy -Dtest=WireMockStatusReporterTest`
4. The above should report no test failures and include the following console output:
`WireMockStatusReporterTest: GitHub proxying and user auth correctly configured for user login: <your login>`
Whenever you run tests with `-Dtest.github.useProxy`, they will try to get data from local files but will fallback to proxying to github if not found.
### Writing a new test
Once you have credentials setup, you add new test classes and test methods as you would normally.
Keep `useProxy` enabled and iterate on your tests as needed. Remember, while proxying your tests are interacting with GitHub - you will need to clean up your state between runs.
When you are ready to create a snapshot of your test data,
run your test with `test.github.takeSnapshot` ("-Dtest.github.takeSnapshot" as a Java VM option). For example:
`mvn install -Dtest.github.takeSnapshot -Dtest=YourTestClassName`
The above command would create snapshot WireMock data files under the path `src/test/resources/org/kohsuhke/github/YourTestClassName/wiremock`.
Each method would get a separate director that would hold the data files for that test method.
Add all files including the generated data to your commit and submit a PR.
### Modifying existing tests
When modifying existing tests, you can change the stubbed WireMock data files by hand or you can try generating a new snapshot.
#### Manual editing of data (minor changes only)
If you know what data will change, it is sometimes simplest to make any required changes to the data files manually.
This can be easier if the changes are minor or when you development environment is not setup to to take updated snapshots.
#### Generating a new snapshot
For more most changes, it is recommended to take a new snapshot when updating tests.
Delete the wiremock data files for the test method you will be modifying.
For more significant changes, you can even delete the WireMock files for an entire test class.
Then follow the same as when writing a new test: run with proxy enabled to debug, take a new snapshot when done, commit everything, and submit the PR.

3
README
View File

@@ -1,3 +0,0 @@
Java API for GitHub
See http://github-api.kohsuke.org/ for more details

3
README.md Normal file
View File

@@ -0,0 +1,3 @@
Java API for GitHub
See https://github-api.kohsuke.org/ for more details

405
pom.xml
View File

@@ -3,63 +3,200 @@
<parent>
<groupId>org.kohsuke</groupId>
<artifactId>pom</artifactId>
<version>14</version>
<version>21</version>
<relativePath />
</parent>
<artifactId>github-api</artifactId>
<version>1.71</version>
<version>1.99</version>
<name>GitHub API for Java</name>
<url>http://github-api.kohsuke.org/</url>
<url>https://github-api.kohsuke.org/</url>
<description>GitHub API for Java</description>
<scm>
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
<url>http://${project.artifactId}.kohsuke.org/</url>
<tag>github-api-1.71</tag>
<connection>scm:git:git@github.com/github-api/${project.artifactId}.git</connection>
<developerConnection>scm:git:ssh://git@github.com/github-api/${project.artifactId}.git</developerConnection>
<url>https://${project.artifactId}.kohsuke.org/</url>
<tag>github-api-1.99</tag>
</scm>
<distributionManagement>
<site>
<id>github-pages</id>
<url>gitsite:git@github.com/kohsuke/${project.artifactId}.git</url>
<url>gitsite:git@github.com/github-api/${project.artifactId}.git</url>
</site>
</distributionManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<findbugs-maven-plugin.version>3.0.2</findbugs-maven-plugin.version>
<findbugs-maven-plugin.failOnError>true</findbugs-maven-plugin.failOnError>
<spotbugs-maven-plugin.version>3.1.12.2</spotbugs-maven-plugin.version>
<spotbugs.version>3.1.12</spotbugs.version>
<spotbugs-maven-plugin.failOnError>true</spotbugs-maven-plugin.failOnError>
<hamcrest.version>2.2</hamcrest.version>
<okhttp3.version>3.12.3</okhttp3.version>
<okio.version>2.4.1</okio.version>
<jacoco.coverage.target.class>.80</jacoco.coverage.target.class>
<jacoco.coverage.target.method>0.20</jacoco.coverage.target.method>
<jacoco.coverage.target.line>0.50</jacoco.coverage.target.line>
<jacoco.coverage.target.other>0.50</jacoco.coverage.target.other>
<!-- For non-ci builds we'd like the build to still complete if jacoco metrics aren't met. -->
<jacoco.haltOnFailure>false</jacoco.haltOnFailure>
</properties>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
<version>1.11.2</version>
</extension>
<extension>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-manager-plexus</artifactId>
<version>1.11.2</version>
</extension>
</extensions>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<excludes>
<exclude>**/wiremock/**</exclude>
</excludes>
</testResource>
</testResources>
<pluginManagement>
<plugins>
<!-- adds jacoco coverage -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<source>8</source>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-injector</artifactId>
<version>1.14</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.8.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>org.apache.bcel</groupId>
<artifactId>bcel</artifactId>
<version>6.4.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.jenkins-ci</groupId>
<artifactId>annotation-indexer</artifactId>
<version>1.12</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.18</version>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java18</artifactId>
<version>1.0</version>
</signature>
</configuration>
<executions>
<execution>
<id>ensure-java-1.8-class-library</id>
<phase>test</phase>
<goals>
<goal>process</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-injector</artifactId>
<version>1.18</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>${findbugs-maven-plugin.version}</version>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
<configuration>
<xmlOutput>true</xmlOutput>
<failOnError>${findbugs-maven-plugin.failOnError}</failOnError>
<failOnError>${spotbugs-maven-plugin.failOnError}</failOnError>
</configuration>
<executions>
<execution>
<id>run-findbugs</id>
<phase>verify</phase>
<id>run-spotbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<!-- overwrite dependency on spotbugs if you want to specify the version of spotbugs -->
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>${spotbugs.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- Do not use gmaven plugin -->
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
@@ -69,35 +206,55 @@
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.7</version>
<version>1.13</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<!-- This is needed in order to force junit4 and JTH tests to use newer hamcrest version -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.3</version>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-annotation</artifactId>
<version>1.14</version>
<version>1.18</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.kohsuke.stapler</groupId>
@@ -108,60 +265,224 @@
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>3.1.0.201310021548-r</version>
<version>5.5.1.201910021850-r</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>${okio.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp3.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-urlconnection</artifactId>
<version>${okhttp3.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp-urlconnection</artifactId>
<version>2.0.0</version>
<version>2.7.5</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>wordnet-random-name</artifactId>
<version>1.2</version>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<artifactId>mockito-core</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
<version>${spotbugs.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8-standalone</artifactId>
<version>2.25.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<profiles>
<profile>
<id>jacoco</id>
<activation>
<property>
<name>enable-jacoco</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>check</id>
<phase>install</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<!--We end up with chatty logs, but it shows us which particular classes -->
<!--are lacking in coverage. If this is too much, just remove the -->
<!--<element>CLASS</element> tag below. -->
<element>CLASS</element>
<limits>
<!-- These limits can be overridden, in the form of `0.50` for -->
<!-- 50%, as necessary. Using a property just puts it in one spot. -->
<!--
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>${jacoco.coverage.target.lines}</minimum>
</limit>
-->
<!--
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>${jacoco.coverage.target.other}</minimum>
</limit>
-->
<!--
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>${jacoco.coverage.target.other}</minimum>
</limit>
-->
<!--
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>${jacoco.coverage.target.other}</minimum>
</limit>
-->
<limit>
<counter>METHOD</counter>
<value>COVEREDRATIO</value>
<minimum>${jacoco.coverage.target.method}</minimum>
</limit>
<!-- <limit>-->
<!-- <counter>CLASS</counter>-->
<!-- <value>COVEREDRATIO</value>-->
<!-- <minimum>${jacoco.coverage.target.class}</minimum>-->
<!-- </limit>-->
</limits>
<excludes>
<exclude>org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory.**</exclude>
<exclude>org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory</exclude>
<exclude>org.kohsuke.github.extras.OkHttp3Connector</exclude>
<!--<exclude>io.jenkins.plugins.todeclarative.converter.api.*</exclude>-->
</excludes>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</plugin>
</plugins>
</reporting>
<licenses>
<license>
<name>The MIT license</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<url>https://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>

View File

@@ -0,0 +1,64 @@
package org.kohsuke.github;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.HttpURLConnection;
/**
* Pluggable strategy to determine what to do when the API abuse limit is hit.
*
* @author Kohsuke Kawaguchi
* @see GitHubBuilder#withAbuseLimitHandler(AbuseLimitHandler)
* @see <a href="https://developer.github.com/v3/#abuse-rate-limits">documentation</a>
* @see RateLimitHandler
*/
public abstract class AbuseLimitHandler {
/**
* Called when the library encounters HTTP error indicating that the API abuse limit is reached.
*
* <p>
* Any exception thrown from this method will cause the request to fail, and the caller of github-api
* will receive an exception. If this method returns normally, another request will be attempted.
* For that to make sense, the implementation needs to wait for some time.
*
* @see <a href="https://developer.github.com/v3/#abuse-rate-limits">API documentation from GitHub</a>
* @param e
* Exception from Java I/O layer. If you decide to fail the processing, you can throw
* this exception (or wrap this exception into another exception and throw it).
* @param uc
* Connection that resulted in an error. Useful for accessing other response headers.
* @throws IOException
*/
public abstract void onError(IOException e, HttpURLConnection uc) throws IOException;
/**
* Wait until the API abuse "wait time" is passed.
*/
public static final AbuseLimitHandler WAIT = new AbuseLimitHandler() {
@Override
public void onError(IOException e, HttpURLConnection uc) throws IOException {
try {
Thread.sleep(parseWaitTime(uc));
} catch (InterruptedException ex) {
throw (InterruptedIOException)new InterruptedIOException().initCause(e);
}
}
private long parseWaitTime(HttpURLConnection uc) {
String v = uc.getHeaderField("Retry-After");
if (v==null) return 60 * 1000; // can't tell, return 1 min
return Math.max(1000, Long.parseLong(v)*1000);
}
};
/**
* Fail immediately.
*/
public static final AbuseLimitHandler FAIL = new AbuseLimitHandler() {
@Override
public void onError(IOException e, HttpURLConnection uc) throws IOException {
throw (IOException)new IOException("Abuse limit reached").initCause(e);
}
};
}

View File

@@ -0,0 +1,17 @@
package org.kohsuke.github;
import java.util.Locale;
/**
* This was added during preview API period but it has changed since then.
*
* @author Kohsuke Kawaguchi
*/
@Deprecated
public enum EnforcementLevel {
OFF, NON_ADMINS, EVERYONE;
public String toString() {
return name().toLowerCase(Locale.ENGLISH);
}
}

View File

@@ -0,0 +1,172 @@
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import static org.kohsuke.github.Previews.MACHINE_MAN;
/**
* A Github App.
*
* @author Paulo Miguel Almeida
*
* @see GitHub#getApp()
*/
public class GHApp extends GHObject {
private GitHub root;
private GHUser owner;
private String name;
private String description;
@JsonProperty("external_url")
private String externalUrl;
private Map<String,String> permissions;
private List<GHEvent> events;
@JsonProperty("installations_count")
private long installationsCount;
@JsonProperty("html_url")
private String htmlUrl;
public GHUser getOwner() {
return owner;
}
public void setOwner(GHUser owner) {
this.owner = owner;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getExternalUrl() {
return externalUrl;
}
public void setExternalUrl(String externalUrl) {
this.externalUrl = externalUrl;
}
public List<GHEvent> getEvents() {
return events;
}
public void setEvents(List<GHEvent> events) {
this.events = events;
}
public long getInstallationsCount() {
return installationsCount;
}
public void setInstallationsCount(long installationsCount) {
this.installationsCount = installationsCount;
}
public URL getHtmlUrl() {
return GitHub.parseURL(htmlUrl);
}
public Map<String, String> getPermissions() {
return permissions;
}
public void setPermissions(Map<String, String> permissions) {
this.permissions = permissions;
}
/*package*/ GHApp wrapUp(GitHub root) {
this.root = root;
return this;
}
/**
* Obtains all the installations associated with this app.
*
* You must use a JWT to access this endpoint.
*
* @see <a href="https://developer.github.com/v3/apps/#list-installations">List installations</a>
* @return a list of App installations
*/
@Preview @Deprecated
public PagedIterable<GHAppInstallation> listInstallations() {
return root.retrieve().withPreview(MACHINE_MAN)
.asPagedIterable(
"/app/installations",
GHAppInstallation[].class,
item -> item.wrapUp(root) );
}
/**
* Obtain an installation associated with this app
* @param id - Installation Id
*
* You must use a JWT to access this endpoint.
*
* @see <a href="https://developer.github.com/v3/apps/#get-an-installation">Get an installation</a>
*/
@Preview @Deprecated
public GHAppInstallation getInstallationById(long id) throws IOException {
return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/app/installations/%d", id), GHAppInstallation.class).wrapUp(root);
}
/**
* Obtain an organization installation associated with this app
* @param name - Organization name
*
* You must use a JWT to access this endpoint.
*
* @see <a href="https://developer.github.com/v3/apps/#get-an-organization-installation">Get an organization installation</a>
*/
@Preview @Deprecated
public GHAppInstallation getInstallationByOrganization(String name) throws IOException {
return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/orgs/%s/installation", name), GHAppInstallation.class).wrapUp(root);
}
/**
* Obtain an repository installation associated with this app
* @param ownerName - Organization or user name
* @param repositoryName - Repository name
*
* You must use a JWT to access this endpoint.
*
* @see <a href="https://developer.github.com/v3/apps/#get-a-repository-installation">Get a repository installation</a>
*/
@Preview @Deprecated
public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) throws IOException {
return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/repos/%s/%s/installation", ownerName, repositoryName), GHAppInstallation.class).wrapUp(root);
}
/**
* Obtain a user installation associated with this app
* @param name - user name
*
* You must use a JWT to access this endpoint.
*
* @see <a href="https://developer.github.com/v3/apps/#get-a-user-installation">Get a user installation</a>
*/
@Preview @Deprecated
public GHAppInstallation getInstallationByUser(String name) throws IOException {
return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/users/%s/installation", name), GHAppInstallation.class).wrapUp(root);
}
}

View File

@@ -0,0 +1,53 @@
package org.kohsuke.github;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import static org.kohsuke.github.Previews.MACHINE_MAN;
/**
* Creates a access token for a GitHub App Installation
*
* @author Paulo Miguel Almeida
*
* @see GHAppInstallation#createToken(Map)
*/
public class GHAppCreateTokenBuilder {
private final GitHub root;
protected final Requester builder;
private final String apiUrlTail;
@Preview @Deprecated
/*package*/ GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map<String, GHPermissionType> permissions) {
this.root = root;
this.apiUrlTail = apiUrlTail;
this.builder = new Requester(root);
this.builder.withPermissions("permissions",permissions);
}
/**
* By default the installation token has access to all repositories that the installation can access. To restrict
* the access to specific repositories, you can provide the repository_ids when creating the token. When you omit
* repository_ids, the response does not contain neither the repositories nor the permissions key.
*
* @param repositoryIds - Array containing the repositories Ids
*
*/
@Preview @Deprecated
public GHAppCreateTokenBuilder repositoryIds(List<Long> repositoryIds) {
this.builder.with("repository_ids",repositoryIds);
return this;
}
/**
* Creates an app token with all the parameters.
*
* You must use a JWT to access this endpoint.
*/
@Preview @Deprecated
public GHAppInstallationToken create() throws IOException {
return builder.method("POST").withPreview(MACHINE_MAN).to(apiUrlTail, GHAppInstallationToken.class).wrapUp(root);
}
}

View File

@@ -0,0 +1,167 @@
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import static org.kohsuke.github.Previews.GAMBIT;
/**
* A Github App Installation.
*
* @author Paulo Miguel Almeida
*
* @see GHApp#listInstallations()
* @see GHApp#getInstallationById(long)
* @see GHApp#getInstallationByOrganization(String)
* @see GHApp#getInstallationByRepository(String, String)
* @see GHApp#getInstallationByUser(String)
*/
public class GHAppInstallation extends GHObject {
private GitHub root;
private GHUser account;
@JsonProperty("access_tokens_url")
private String accessTokenUrl;
@JsonProperty("repositories_url")
private String repositoriesUrl;
@JsonProperty("app_id")
private long appId;
@JsonProperty("target_id")
private long targetId;
@JsonProperty("target_type")
private GHTargetType targetType;
private Map<String, GHPermissionType> permissions;
private List<GHEvent> events;
@JsonProperty("single_file_name")
private String singleFileName;
@JsonProperty("repository_selection")
private GHRepositorySelection repositorySelection;
private String htmlUrl;
public URL getHtmlUrl() {
return GitHub.parseURL(htmlUrl);
}
public GitHub getRoot() {
return root;
}
public void setRoot(GitHub root) {
this.root = root;
}
public GHUser getAccount() {
return account;
}
public void setAccount(GHUser account) {
this.account = account;
}
public String getAccessTokenUrl() {
return accessTokenUrl;
}
public void setAccessTokenUrl(String accessTokenUrl) {
this.accessTokenUrl = accessTokenUrl;
}
public String getRepositoriesUrl() {
return repositoriesUrl;
}
public void setRepositoriesUrl(String repositoriesUrl) {
this.repositoriesUrl = repositoriesUrl;
}
public long getAppId() {
return appId;
}
public void setAppId(long appId) {
this.appId = appId;
}
public long getTargetId() {
return targetId;
}
public void setTargetId(long targetId) {
this.targetId = targetId;
}
public GHTargetType getTargetType() {
return targetType;
}
public void setTargetType(GHTargetType targetType) {
this.targetType = targetType;
}
public Map<String, GHPermissionType> getPermissions() {
return permissions;
}
public void setPermissions(Map<String, GHPermissionType> permissions) {
this.permissions = permissions;
}
public List<GHEvent> getEvents() {
return events;
}
public void setEvents(List<GHEvent> events) {
this.events = events;
}
public String getSingleFileName() {
return singleFileName;
}
public void setSingleFileName(String singleFileName) {
this.singleFileName = singleFileName;
}
public GHRepositorySelection getRepositorySelection() {
return repositorySelection;
}
public void setRepositorySelection(GHRepositorySelection repositorySelection) {
this.repositorySelection = repositorySelection;
}
/*package*/ GHAppInstallation wrapUp(GitHub root) {
this.root = root;
return this;
}
/**
* Delete a Github App installation
*
* You must use a JWT to access this endpoint.
*
* @see <a href="https://developer.github.com/v3/apps/#delete-an-installation">Delete an installation</a>
*/
@Preview @Deprecated
public void deleteInstallation() throws IOException {
root.retrieve().method("DELETE").withPreview(GAMBIT).to(String.format("/app/installations/%d", id));
}
/**
* Starts a builder that creates a new App Installation Token.
*
* <p>
* You use the returned builder to set various properties, then call {@link GHAppCreateTokenBuilder#create()}
* to finally create an access token.
*/
@Preview @Deprecated
public GHAppCreateTokenBuilder createToken(Map<String,GHPermissionType> permissions){
return new GHAppCreateTokenBuilder(root,String.format("/app/installations/%d/access_tokens", id), permissions);
}
}

View File

@@ -0,0 +1,87 @@
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* A Github App Installation Token.
*
* @author Paulo Miguel Almeida
*
* @see GHAppInstallation#createToken(Map)
*/
public class GHAppInstallationToken {
private GitHub root;
private String token;
protected String expires_at;
private Map<String, String> permissions;
private List<GHRepository> repositories;
@JsonProperty("repository_selection")
private GHRepositorySelection repositorySelection;
public GitHub getRoot() {
return root;
}
public void setRoot(GitHub root) {
this.root = root;
}
public Map<String, String> getPermissions() {
return permissions;
}
public void setPermissions(Map<String, String> permissions) {
this.permissions = permissions;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public List<GHRepository> getRepositories() {
return repositories;
}
public void setRepositories(List<GHRepository> repositories) {
this.repositories = repositories;
}
public GHRepositorySelection getRepositorySelection() {
return repositorySelection;
}
public void setRepositorySelection(GHRepositorySelection repositorySelection) {
this.repositorySelection = repositorySelection;
}
/**
* When was this tokens expires?
*/
@WithBridgeMethods(value=String.class, adapterMethod="expiresAtStr")
public Date getExpiresAt() throws IOException {
return GitHub.parseDate(expires_at);
}
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getExpiresAt")
private Object expiresAtStr(Date id, Class type) {
return expires_at;
}
/*package*/ GHAppInstallationToken wrapUp(GitHub root) {
this.root = root;
return this;
}
}

View File

@@ -1,9 +1,9 @@
package org.kohsuke.github;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.net.URL;
import java.util.Collection;
import java.util.Date;
import java.util.List;
/**
@@ -36,9 +36,14 @@ public class GHAuthorization extends GHObject {
private GitHub root;
private List<String> scopes;
private String token;
private String token_last_eight;
private String hashed_token;
private App app;
private String note;
private String note_url;
private String fingerprint;
//TODO add some user class for https://developer.github.com/v3/oauth_authorizations/#check-an-authorization ?
//private GHUser user;
public GitHub getRoot() {
return root;
@@ -52,6 +57,14 @@ public class GHAuthorization extends GHObject {
return token;
}
public String getTokenLastEight() {
return token_last_eight;
}
public String getHashedToken() {
return hashed_token;
}
public URL getAppUrl() {
return GitHub.parseURL(app.url);
}
@@ -82,6 +95,10 @@ public class GHAuthorization extends GHObject {
return GitHub.parseURL(note_url);
}
public String getFingerprint() {
return fingerprint;
}
/*package*/ GHAuthorization wrap(GitHub root) {
this.root = root;
return this;
@@ -92,5 +109,6 @@ public class GHAuthorization extends GHObject {
private static class App {
private String url;
private String name;
// private String client_id; not yet used
}
}

View File

@@ -0,0 +1,64 @@
package org.kohsuke.github;
import org.apache.commons.codec.binary.Base64InputStream;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
/**
* @author Kanstantsin Shautsou
* @author Kohsuke Kawaguchi
* @see GHTreeEntry#asBlob()
* @see GHRepository#getBlob(String)
* @see <a href="https://developer.github.com/v3/git/blobs/#get-a-blob">Get a blob</a>
*/
public class GHBlob {
private String content, encoding, url, sha;
private long size;
/**
* API URL of this blob.
*/
public URL getUrl() {
return GitHub.parseURL(url);
}
public String getSha() {
return sha;
}
/**
* Number of bytes in this blob.
*/
public long getSize() {
return size;
}
public String getEncoding() {
return encoding;
}
/**
* Encoded content. You probably want {@link #read()}
*/
public String getContent() {
return content;
}
/**
* Retrieves the actual bytes of the blob.
*/
public InputStream read() {
if (encoding.equals("base64")) {
try {
return new Base64InputStream(new ByteArrayInputStream(content.getBytes("US-ASCII")), false);
} catch (UnsupportedEncodingException e) {
throw new AssertionError(e); // US-ASCII is mandatory
}
}
throw new UnsupportedOperationException("Unrecognized encoding: "+encoding);
}
}

View File

@@ -0,0 +1,49 @@
package org.kohsuke.github;
import org.apache.commons.codec.binary.Base64;
import java.io.IOException;
/**
* Builder pattern for creating a new blob.
* Based on https://developer.github.com/v3/git/blobs/#create-a-blob
*/
public class GHBlobBuilder {
private final GHRepository repo;
private final Requester req;
GHBlobBuilder(GHRepository repo) {
this.repo = repo;
req = new Requester(repo.root);
}
/**
* Configures a blob with the specified text {@code content}.
*/
public GHBlobBuilder textContent(String content) {
req.with("content", content);
req.with("encoding", "utf-8");
return this;
}
/**
* Configures a blob with the specified binary {@code content}.
*/
public GHBlobBuilder binaryContent(byte[] content) {
String base64Content = Base64.encodeBase64String(content);
req.with("content", base64Content);
req.with("encoding", "base64");
return this;
}
private String getApiTail() {
return String.format("/repos/%s/%s/git/blobs", repo.getOwnerName(), repo.getName());
}
/**
* Creates a blob based on the parameters specified thus far.
*/
public GHBlob create() throws IOException {
return req.method("POST").to(getApiTail(), GHBlob.class);
}
}

View File

@@ -1,24 +1,35 @@
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.net.URL;
import java.util.Collection;
import static org.kohsuke.github.Previews.*;
/**
* A branch in a repository.
*
*
* @author Yusuke Kokubo
*/
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD"}, justification = "JSON API")
public class GHBranch {
private GitHub root;
private GHRepository owner;
private String name;
private Commit commit;
@JsonProperty("protected")
private boolean protection;
private String protection_url;
public static class Commit {
String sha;
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
String url;
}
@@ -38,13 +49,71 @@ public class GHBranch {
return name;
}
/**
* Returns true if the push to this branch is restricted via branch protection.
*/
@Preview @Deprecated
public boolean isProtected() {
return protection;
}
/**
* Returns API URL that deals with the protection of this branch.
*/
@Preview @Deprecated
public URL getProtectionUrl() {
return GitHub.parseURL(protection_url);
}
public GHBranchProtection getProtection() throws IOException {
return root.retrieve().to(protection_url, GHBranchProtection.class).wrap(this);
}
/**
* The commit that this branch currently points to.
*/
public String getSHA1() {
return commit.sha;
}
/**
* Disables branch protection and allows anyone with push access to push changes.
*/
public void disableProtection() throws IOException {
new Requester(root).method("DELETE").to(protection_url);
}
/**
* Enables branch protection to control what commit statuses are required to push.
*
* @see GHCommitStatus#getContext()
*/
@Preview @Deprecated
public GHBranchProtectionBuilder enableProtection() {
return new GHBranchProtectionBuilder(this);
}
// backward compatibility with previous signature
@Deprecated
public void enableProtection(EnforcementLevel level, Collection<String> contexts) throws IOException {
switch (level) {
case OFF:
disableProtection();
break;
case NON_ADMINS:
case EVERYONE:
enableProtection()
.addRequiredChecks(contexts)
.includeAdmins(level==EnforcementLevel.EVERYONE)
.enable();
break;
}
}
String getApiRoute() {
return owner.getApiTailUrl("/branches/"+name);
}
@Override
public String toString() {
final String url = owner != null ? owner.getUrl().toString() : "unknown";

View File

@@ -0,0 +1,208 @@
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import static org.kohsuke.github.Previews.ZZZAX;
import java.io.IOException;
import java.util.Collection;
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
"URF_UNREAD_FIELD"}, justification = "JSON API")
public class GHBranchProtection {
private static final String REQUIRE_SIGNATURES_URI = "/required_signatures";
@JsonProperty("enforce_admins")
private EnforceAdmins enforceAdmins;
private GitHub root;
@JsonProperty("required_pull_request_reviews")
private RequiredReviews requiredReviews;
@JsonProperty("required_status_checks")
private RequiredStatusChecks requiredStatusChecks;
@JsonProperty
private Restrictions restrictions;
@JsonProperty
private String url;
@Preview @Deprecated
public void enabledSignedCommits() throws IOException {
requester().method("POST")
.to(url + REQUIRE_SIGNATURES_URI, RequiredSignatures.class);
}
@Preview @Deprecated
public void disableSignedCommits() throws IOException {
requester().method("DELETE")
.to(url + REQUIRE_SIGNATURES_URI);
}
public EnforceAdmins getEnforceAdmins() {
return enforceAdmins;
}
public RequiredReviews getRequiredReviews() {
return requiredReviews;
}
@Preview @Deprecated
public boolean getRequiredSignatures() throws IOException {
return requester().method("GET")
.to(url + REQUIRE_SIGNATURES_URI, RequiredSignatures.class).enabled;
}
public RequiredStatusChecks getRequiredStatusChecks() {
return requiredStatusChecks;
}
public Restrictions getRestrictions() {
return restrictions;
}
public String getUrl() {
return url;
}
GHBranchProtection wrap(GHBranch branch) {
this.root = branch.getRoot();
return this;
}
private Requester requester() {
return new Requester(root).withPreview(ZZZAX);
}
public static class EnforceAdmins {
@JsonProperty
private boolean enabled;
@JsonProperty
private String url;
public String getUrl() {
return url;
}
public boolean isEnabled() {
return enabled;
}
}
public static class RequiredReviews {
@JsonProperty("dismissal_restrictions")
private Restrictions dismissalRestriction;
@JsonProperty("dismiss_stale_reviews")
private boolean dismissStaleReviews;
@JsonProperty("require_code_owner_reviews")
private boolean requireCodeOwnerReviews;
@JsonProperty("required_approving_review_count")
private int requiredReviewers;
@JsonProperty
private String url;
public Restrictions getDismissalRestrictions() {
return dismissalRestriction;
}
public String getUrl() {
return url;
}
public boolean isDismissStaleReviews() {
return dismissStaleReviews;
}
public boolean isRequireCodeOwnerReviews() {
return requireCodeOwnerReviews;
}
public int getRequiredReviewers() {
return requiredReviewers;
}
}
private static class RequiredSignatures {
@JsonProperty
private boolean enabled;
@JsonProperty
private String url;
public String getUrl() {
return url;
}
public boolean isEnabled() {
return enabled;
}
}
public static class RequiredStatusChecks {
@JsonProperty
private Collection<String> contexts;
@JsonProperty
private boolean strict;
@JsonProperty
private String url;
public Collection<String> getContexts() {
return contexts;
}
public String getUrl() {
return url;
}
public boolean isRequiresBranchUpToDate() {
return strict;
}
}
public static class Restrictions {
@JsonProperty
private Collection<GHTeam> teams;
@JsonProperty("teams_url")
private String teamsUrl;
@JsonProperty
private String url;
@JsonProperty
private Collection<GHUser> users;
@JsonProperty("users_url")
private String usersUrl;
public Collection<GHTeam> getTeams() {
return teams;
}
public String getTeamsUrl() {
return teamsUrl;
}
public String getUrl() {
return url;
}
public Collection<GHUser> getUsers() {
return users;
}
public String getUsersUrl() {
return usersUrl;
}
}
}

View File

@@ -0,0 +1,218 @@
package org.kohsuke.github;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.kohsuke.github.Previews.*;
/**
* Builder to configure the branch protection settings.
*
* @see GHBranch#enableProtection()
*/
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
"URF_UNREAD_FIELD" }, justification = "JSON API")
public class GHBranchProtectionBuilder {
private final GHBranch branch;
private boolean enforceAdmins;
private Map<String, Object> prReviews;
private Restrictions restrictions;
private StatusChecks statusChecks;
GHBranchProtectionBuilder(GHBranch branch) {
this.branch = branch;
}
public GHBranchProtectionBuilder addRequiredChecks(Collection<String> checks) {
getStatusChecks().contexts.addAll(checks);
return this;
}
public GHBranchProtectionBuilder addRequiredChecks(String... checks) {
addRequiredChecks(Arrays.asList(checks));
return this;
}
public GHBranchProtectionBuilder dismissStaleReviews() {
return dismissStaleReviews(true);
}
public GHBranchProtectionBuilder dismissStaleReviews(boolean v) {
getPrReviews().put("dismiss_stale_reviews", v);
return this;
}
public GHBranchProtection enable() throws IOException {
return requester().method("PUT")
.withNullable("required_status_checks", statusChecks)
.withNullable("required_pull_request_reviews", prReviews)
.withNullable("restrictions", restrictions)
.withNullable("enforce_admins", enforceAdmins)
.to(branch.getProtectionUrl().toString(), GHBranchProtection.class)
.wrap(branch);
}
public GHBranchProtectionBuilder includeAdmins() {
return includeAdmins(true);
}
public GHBranchProtectionBuilder includeAdmins(boolean v) {
enforceAdmins = v;
return this;
}
public GHBranchProtectionBuilder requiredReviewers(int v) {
getPrReviews().put("required_approving_review_count", v);
return this;
}
public GHBranchProtectionBuilder requireBranchIsUpToDate() {
return requireBranchIsUpToDate(true);
}
public GHBranchProtectionBuilder requireBranchIsUpToDate(boolean v) {
getStatusChecks().strict = v;
return this;
}
public GHBranchProtectionBuilder requireCodeOwnReviews() {
return requireCodeOwnReviews(true);
}
public GHBranchProtectionBuilder requireCodeOwnReviews(boolean v) {
getPrReviews().put("require_code_owner_reviews", v);
return this;
}
public GHBranchProtectionBuilder requireReviews() {
getPrReviews();
return this;
}
public GHBranchProtectionBuilder restrictReviewDismissals() {
getPrReviews();
if (!prReviews.containsKey("dismissal_restrictions")) {
prReviews.put("dismissal_restrictions", new Restrictions());
}
return this;
}
public GHBranchProtectionBuilder restrictPushAccess() {
getRestrictions();
return this;
}
public GHBranchProtectionBuilder teamPushAccess(Collection<GHTeam> teams) {
for (GHTeam team : teams) {
teamPushAccess(team);
}
return this;
}
public GHBranchProtectionBuilder teamPushAccess(GHTeam... teams) {
for (GHTeam team : teams) {
getRestrictions().teams.add(team.getSlug());
}
return this;
}
public GHBranchProtectionBuilder teamReviewDismissals(Collection<GHTeam> teams) {
for (GHTeam team : teams) {
teamReviewDismissals(team);
}
return this;
}
public GHBranchProtectionBuilder teamReviewDismissals(GHTeam... teams) {
for (GHTeam team : teams) {
addReviewRestriction(team.getSlug(), true);
}
return this;
}
public GHBranchProtectionBuilder userPushAccess(Collection<GHUser> users) {
for (GHUser user : users) {
userPushAccess(user);
}
return this;
}
public GHBranchProtectionBuilder userPushAccess(GHUser... users) {
for (GHUser user : users) {
getRestrictions().users.add(user.getLogin());
}
return this;
}
public GHBranchProtectionBuilder userReviewDismissals(Collection<GHUser> users) {
for (GHUser team : users) {
userReviewDismissals(team);
}
return this;
}
public GHBranchProtectionBuilder userReviewDismissals(GHUser... users) {
for (GHUser user : users) {
addReviewRestriction(user.getLogin(), false);
}
return this;
}
private void addReviewRestriction(String restriction, boolean isTeam) {
restrictReviewDismissals();
Restrictions restrictions = (Restrictions) prReviews.get("dismissal_restrictions");
if (isTeam) {
restrictions.teams.add(restriction);
} else {
restrictions.users.add(restriction);
}
}
private Map<String, Object> getPrReviews() {
if (prReviews == null) {
prReviews = new HashMap<String, Object>();
}
return prReviews;
}
private Restrictions getRestrictions() {
if (restrictions == null) {
restrictions = new Restrictions();
}
return restrictions;
}
private StatusChecks getStatusChecks() {
if (statusChecks == null) {
statusChecks = new StatusChecks();
}
return statusChecks;
}
private Requester requester() {
return new Requester(branch.getRoot()).withPreview(LUKE_CAGE);
}
private static class Restrictions {
private Set<String> teams = new HashSet<String>();
private Set<String> users = new HashSet<String>();
}
private static class StatusChecks {
final List<String> contexts = new ArrayList<String>();
boolean strict;
}
}

View File

@@ -0,0 +1,37 @@
package org.kohsuke.github;
/**
* How is an user associated with a repository?
*
* @author Kohsuke Kawaguchi
*/
public enum GHCommentAuthorAssociation {
/**
* Author has been invited to collaborate on the repository.
*/
COLLABORATOR,
/**
* Author has previously committed to the repository.
*/
CONTRIBUTOR,
/**
* Author has not previously committed to GitHub.
*/
FIRST_TIMER,
/**
* Author has not previously committed to the repository.
*/
FIRST_TIME_CONTRIBUTOR,
/**
* Author is a member of the organization that owns the repository.
*/
MEMBER,
/**
* Author has no association with the repository.
*/
NONE,
/**
* Author is the owner of the repository.
*/
OWNER
}

View File

@@ -8,6 +8,7 @@ import java.net.URL;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
/**
@@ -37,16 +38,30 @@ public class GHCommit {
private int comment_count;
static class Tree {
String sha;
}
private Tree tree;
@WithBridgeMethods(value = GHAuthor.class, castRequired = true)
public GitUser getAuthor() {
return author;
}
public Date getAuthoredDate() {
return GitHub.parseDate(author.date);
}
@WithBridgeMethods(value = GHAuthor.class, castRequired = true)
public GitUser getCommitter() {
return committer;
}
public Date getCommitDate() {
return GitHub.parseDate(committer.date);
}
/**
* Commit message.
*/
@@ -63,6 +78,7 @@ public class GHCommit {
* @deprecated Use {@link GitUser} instead.
*/
public static class GHAuthor extends GitUser {
private String date;
}
public static class Stats {
@@ -102,7 +118,7 @@ public class GHCommit {
}
/**
* "modified", "added", or "deleted"
* "modified", "added", or "removed"
*/
public String getStatus() {
return status;
@@ -171,14 +187,16 @@ public class GHCommit {
String login;
}
String url,sha;
String url,html_url,sha;
List<File> files;
Stats stats;
List<Parent> parents;
User author,committer;
public ShortInfo getCommitShortInfo() {
public ShortInfo getCommitShortInfo() throws IOException {
if (commit==null)
populate();
return commit;
}
@@ -192,24 +210,41 @@ public class GHCommit {
/**
* Number of lines added + removed.
*/
public int getLinesChanged() {
public int getLinesChanged() throws IOException {
populate();
return stats.total;
}
/**
* Number of lines added.
*/
public int getLinesAdded() {
public int getLinesAdded() throws IOException {
populate();
return stats.additions;
}
/**
* Number of lines removed.
*/
public int getLinesDeleted() {
public int getLinesDeleted() throws IOException {
populate();
return stats.deletions;
}
/**
* Use this method to walk the tree
*/
public GHTree getTree() throws IOException {
return owner.getTree(getCommitShortInfo().tree.sha);
}
/**
* URL of this commit like "https://github.com/kohsuke/sandbox-ant/commit/8ae38db0ea5837313ab5f39d43a6f73de3bd9000"
*/
public URL getHtmlUrl() {
return GitHub.parseURL(html_url);
}
/**
* [0-9a-f]{40} SHA1 checksum.
*/
@@ -223,7 +258,8 @@ public class GHCommit {
* @return
* Can be empty but never null.
*/
public List<File> getFiles() {
public List<File> getFiles() throws IOException {
populate();
return files!=null ? Collections.unmodifiableList(files) : Collections.<File>emptyList();
}
@@ -259,10 +295,29 @@ public class GHCommit {
return resolveUser(author);
}
/**
* Gets the date the change was authored on.
* @return the date the change was authored on.
* @throws IOException if the information was not already fetched and an attempt at fetching the information failed.
*/
public Date getAuthoredDate() throws IOException {
return getCommitShortInfo().getAuthoredDate();
}
public GHUser getCommitter() throws IOException {
return resolveUser(committer);
}
/**
* Gets the date the change was committed on.
*
* @return the date the change was committed on.
* @throws IOException if the information was not already fetched and an attempt at fetching the information failed.
*/
public Date getCommitDate() throws IOException {
return getCommitShortInfo().getCommitDate();
}
private GHUser resolveUser(User author) throws IOException {
if (author==null || author.login==null) return null;
return owner.root.getUser(author.login);
@@ -272,17 +327,11 @@ public class GHCommit {
* Lists up all the commit comments in this repository.
*/
public PagedIterable<GHCommitComment> listComments() {
return new PagedIterable<GHCommitComment>() {
public PagedIterator<GHCommitComment> iterator() {
return new PagedIterator<GHCommitComment>(owner.root.retrieve().asIterator(String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha), GHCommitComment[].class)) {
@Override
protected void wrapUp(GHCommitComment[] page) {
for (GHCommitComment c : page)
c.wrap(owner);
}
};
}
};
return owner.root.retrieve()
.asPagedIterable(
String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha),
GHCommitComment[].class,
item -> item.wrap(owner) );
}
/**
@@ -301,7 +350,7 @@ public class GHCommit {
}
public GHCommitComment createComment(String body) throws IOException {
return createComment(body,null,null,null);
return createComment(body, null, null, null);
}
/**
@@ -318,6 +367,14 @@ public class GHCommit {
return owner.getLastCommitStatus(sha);
}
/**
* Some of the fields are not always filled in when this object is retrieved as a part of another API call.
*/
void populate() throws IOException {
if (files==null && stats==null)
owner.root.retrieve().to(owner.getApiTailUrl("commits/" + sha), this);
}
GHCommit wrapUp(GHRepository owner) {
this.owner = owner;
return this;

View File

@@ -0,0 +1,92 @@
package org.kohsuke.github;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
/**
* Builder pattern for creating a new commit.
* Based on https://developer.github.com/v3/git/commits/#create-a-commit
*/
public class GHCommitBuilder {
private final GHRepository repo;
private final Requester req;
private final List<String> parents = new ArrayList<String>();
private static final class UserInfo {
private final String name;
private final String email;
private final String date;
private UserInfo(String name, String email, Date date) {
this.name = name;
this.email = email;
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
df.setTimeZone(tz);
this.date = df.format((date != null) ? date : new Date());
}
}
GHCommitBuilder(GHRepository repo) {
this.repo = repo;
req = new Requester(repo.root);
}
/**
* @param message the commit message
*/
public GHCommitBuilder message(String message) {
req.with("message", message);
return this;
}
/**
* @param tree the SHA of the tree object this commit points to
*/
public GHCommitBuilder tree(String tree) {
req.with("tree", tree);
return this;
}
/**
* @param parent the SHA of a parent commit.
*/
public GHCommitBuilder parent(String parent) {
parents.add(parent);
return this;
}
/**
* Configures the author of this commit.
*/
public GHCommitBuilder author(String name, String email, Date date) {
req._with("author", new UserInfo(name, email, date));
return this;
}
/**
* Configures the committer of this commit.
*/
public GHCommitBuilder committer(String name, String email, Date date) {
req._with("committer", new UserInfo(name, email, date));
return this;
}
private String getApiTail() {
return String.format("/repos/%s/%s/git/commits", repo.getOwnerName(), repo.getName());
}
/**
* Creates a blob based on the parameters specified thus far.
*/
public GHCommit create() throws IOException {
req._with("parents", parents);
return req.method("POST").to(getApiTail(), GHCommit.class).wrapUp(repo);
}
}

View File

@@ -1,9 +1,11 @@
package org.kohsuke.github;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.net.URL;
import java.util.Date;
import static org.kohsuke.github.Previews.*;
/**
* A comment attached to a commit (or a specific line in a specific file of a commit.)
@@ -15,23 +17,13 @@ import java.util.Date;
*/
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
public class GHCommitComment extends GHObject {
public class GHCommitComment extends GHObject implements Reactable {
private GHRepository owner;
String body, html_url, commit_id;
Integer line;
String path;
User user;
static class User {
// TODO: what if someone who doesn't have an account on GitHub makes a commit?
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
String url,avatar_url,gravatar_id;
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
int id;
String login;
}
GHUser user; // not fully populated. beware.
public GHRepository getOwner() {
return owner;
@@ -76,7 +68,7 @@ public class GHCommitComment extends GHObject {
* Gets the user who put this comment.
*/
public GHUser getUser() throws IOException {
return owner.root.getUser(user.login);
return owner == null || owner.root.isOffline() ? user : owner.root.getUser(user.login);
}
/**
@@ -96,6 +88,23 @@ public class GHCommitComment extends GHObject {
this.body = body;
}
@Preview @Deprecated
public GHReaction createReaction(ReactionContent content) throws IOException {
return new Requester(owner.root)
.withPreview(SQUIRREL_GIRL)
.with("content", content.getContent())
.to(getApiTail()+"/reactions", GHReaction.class).wrap(owner.root);
}
@Preview @Deprecated
public PagedIterable<GHReaction> listReactions() {
return owner.root.retrieve().withPreview(SQUIRREL_GIRL)
.asPagedIterable(
getApiTail()+"/reactions",
GHReaction[].class,
item -> item.wrap(owner.root) );
}
/**
* Deletes this comment.
*/
@@ -110,6 +119,9 @@ public class GHCommitComment extends GHObject {
GHCommitComment wrap(GHRepository owner) {
this.owner = owner;
if (owner.root.isOffline()) {
user.wrapUp(owner.root);
}
return this;
}
}

View File

@@ -39,7 +39,8 @@ public class GHCommitPointer {
* This points to the user who owns
* the {@link #getRepository()}.
*/
public GHUser getUser() {
public GHUser getUser() throws IOException {
if (user != null) return user.root.intern(user);
return user;
}

View File

@@ -91,15 +91,10 @@ public class GHCommitQueryBuilder {
* Lists up the commits with the criteria built so far.
*/
public PagedIterable<GHCommit> list() {
return new PagedIterable<GHCommit>() {
public PagedIterator<GHCommit> iterator() {
return new PagedIterator<GHCommit>(req.asIterator(repo.getApiTailUrl("commits"), GHCommit[].class)) {
protected void wrapUp(GHCommit[] page) {
for (GHCommit c : page)
c.wrapUp(repo);
}
};
}
};
return req
.asPagedIterable(
repo.getApiTailUrl("commits"),
GHCommit[].class,
item -> item.wrapUp(repo) );
}
}

View File

@@ -0,0 +1,137 @@
package org.kohsuke.github;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
/**
* Search commits.
*
* @author Marc de Verdelhan
* @see GitHub#searchCommits()
*/
@Preview @Deprecated
public class GHCommitSearchBuilder extends GHSearchBuilder<GHCommit> {
/*package*/ GHCommitSearchBuilder(GitHub root) {
super(root,CommitSearchResult.class);
req.withPreview(Previews.CLOAK);
}
/**
* Search terms.
*/
public GHCommitSearchBuilder q(String term) {
super.q(term);
return this;
}
public GHCommitSearchBuilder author(String v) {
return q("author:"+v);
}
public GHCommitSearchBuilder committer(String v) {
return q("committer:"+v);
}
public GHCommitSearchBuilder authorName(String v) {
return q("author-name:"+v);
}
public GHCommitSearchBuilder committerName(String v) {
return q("committer-name:"+v);
}
public GHCommitSearchBuilder authorEmail(String v) {
return q("author-email:"+v);
}
public GHCommitSearchBuilder committerEmail(String v) {
return q("committer-email:"+v);
}
public GHCommitSearchBuilder authorDate(String v) {
return q("author-date:"+v);
}
public GHCommitSearchBuilder committerDate(String v) {
return q("committer-date:"+v);
}
public GHCommitSearchBuilder merge(boolean merge) {
return q("merge:"+Boolean.valueOf(merge).toString().toLowerCase());
}
public GHCommitSearchBuilder hash(String v) {
return q("hash:"+v);
}
public GHCommitSearchBuilder parent(String v) {
return q("parent:"+v);
}
public GHCommitSearchBuilder tree(String v) {
return q("tree:"+v);
}
public GHCommitSearchBuilder is(String v) {
return q("is:"+v);
}
public GHCommitSearchBuilder user(String v) {
return q("user:"+v);
}
public GHCommitSearchBuilder org(String v) {
return q("org:"+v);
}
public GHCommitSearchBuilder repo(String v) {
return q("repo:"+v);
}
public GHCommitSearchBuilder order(GHDirection v) {
req.with("order",v);
return this;
}
public GHCommitSearchBuilder sort(Sort sort) {
req.with("sort",sort);
return this;
}
public enum Sort { AUTHOR_DATE, COMMITTER_DATE }
private static class CommitSearchResult extends SearchResult<GHCommit> {
private GHCommit[] items;
@Override
/*package*/ GHCommit[] getItems(GitHub root) {
for (GHCommit commit : items) {
String repoName = getRepoName(commit.url);
try {
GHRepository repo = root.getRepository(repoName);
commit.wrapUp(repo);
} catch (IOException ioe) {}
}
return items;
}
}
/**
* @param commitUrl a commit URL
* @return the repo name ("username/reponame")
*/
private static String getRepoName(String commitUrl) {
if (StringUtils.isBlank(commitUrl)) {
return null;
}
int indexOfUsername = (GitHub.GITHUB_URL + "/repos/").length();
String[] tokens = commitUrl.substring(indexOfUsername).split("/", 3);
return tokens[0] + '/' + tokens[1];
}
@Override
protected String getApiUrl() {
return "/search/commits";
}
}

View File

@@ -2,7 +2,6 @@ package org.kohsuke.github;
import java.io.IOException;
import java.net.URL;
import java.util.Date;
/**
* Represents a status of a commit.
@@ -10,6 +9,7 @@ import java.util.Date;
* @author Kohsuke Kawaguchi
* @see GHRepository#getLastCommitStatus(String)
* @see GHCommit#getLastStatus()
* @see GHRepository#createCommitStatus(String, GHCommitState, String, String)
*/
public class GHCommitStatus extends GHObject {
String state;
@@ -46,8 +46,8 @@ public class GHCommitStatus extends GHObject {
return description;
}
public GHUser getCreator() {
return creator;
public GHUser getCreator() throws IOException {
return root.intern(creator);
}
public String getContext() {

View File

@@ -4,8 +4,6 @@ import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.net.URL;
import java.util.Arrays;
import java.util.Date;
/**
* The model user for comparing 2 commits in the GitHub API.
@@ -72,7 +70,9 @@ public class GHCompare {
* @return A copy of the array being stored in the class.
*/
public Commit[] getCommits() {
return Arrays.copyOf(commits, commits.length);
Commit[] newValue = new Commit[commits.length];
System.arraycopy(commits, 0, newValue, 0, commits.length);
return newValue;
}
/**
@@ -80,7 +80,9 @@ public class GHCompare {
* @return A copy of the array being stored in the class.
*/
public GHCommit.File[] getFiles() {
return Arrays.copyOf(files, files.length);
GHCommit.File[] newValue = new GHCommit.File[files.length];
System.arraycopy(files, 0, newValue, 0, files.length);
return newValue;
}
public GHCompare wrap(GHRepository owner) {

View File

@@ -2,12 +2,12 @@ package org.kohsuke.github;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.apache.commons.codec.binary.Base64InputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.bind.DatatypeConverter;
import java.io.UnsupportedEncodingException;
/**
* A Content of a repository.
@@ -16,7 +16,7 @@ import javax.xml.bind.DatatypeConverter;
* @see GHRepository#getFileContent(String)
*/
@SuppressWarnings({"UnusedDeclaration"})
public class GHContent {
public class GHContent implements Refreshable {
/*
In normal use of this class, repository field is set via wrap(),
but in the code search API, there's a nested 'repository' field that gets populated from JSON.
@@ -78,7 +78,7 @@ public class GHContent {
*/
@SuppressFBWarnings("DM_DEFAULT_ENCODING")
public String getContent() throws IOException {
return new String(DatatypeConverter.parseBase64Binary(getEncodedContent()));
return new String(Base64.decodeBase64(getEncodedContent()));
}
/**
@@ -93,10 +93,8 @@ public class GHContent {
* Use {@link #read()}
*/
public String getEncodedContent() throws IOException {
if (content!=null)
return content;
else
return Base64.encodeBase64String(IOUtils.toByteArray(read()));
refresh(content);
return content;
}
public String getUrl() {
@@ -114,15 +112,27 @@ public class GHContent {
/**
* Retrieves the actual content stored here.
*/
/**
* Retrieves the actual bytes of the blob.
*/
public InputStream read() throws IOException {
return new Requester(root).asStream(getDownloadUrl());
refresh(content);
if (encoding.equals("base64")) {
try {
return new Base64InputStream(new ByteArrayInputStream(content.getBytes("US-ASCII")), false);
} catch (UnsupportedEncodingException e) {
throw new AssertionError(e); // US-ASCII is mandatory
}
}
throw new UnsupportedOperationException("Unrecognized encoding: "+encoding);
}
/**
* URL to retrieve the raw content of the file. Null if this is a directory.
*/
public String getDownloadUrl() throws IOException {
populate();
refresh(download_url);
return download_url;
}
@@ -140,7 +150,6 @@ public class GHContent {
* Depending on the original API call where this object is created, it may not contain everything.
*/
protected synchronized void populate() throws IOException {
if (download_url!=null) return; // already populated
root.retrieve().to(url, this);
}
@@ -151,16 +160,11 @@ public class GHContent {
if (!isDirectory())
throw new IllegalStateException(path+" is not a directory");
return new PagedIterable<GHContent>() {
public PagedIterator<GHContent> iterator() {
return new PagedIterator<GHContent>(root.retrieve().asIterator(url, GHContent[].class)) {
@Override
protected void wrapUp(GHContent[] page) {
GHContent.wrap(page, repository);
}
};
}
};
return root.retrieve()
.asPagedIterable(
url,
GHContent[].class,
item -> item.wrap(repository) );
}
@SuppressFBWarnings("DM_DEFAULT_ENCODING")
@@ -178,7 +182,7 @@ public class GHContent {
}
public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessage, String branch) throws IOException {
String encodedContent = DatatypeConverter.printBase64Binary(newContentBytes);
String encodedContent = Base64.encodeBase64String(newContentBytes);
Requester requester = new Requester(root)
.with("path", path)
@@ -244,4 +248,14 @@ public class GHContent {
}
return contents;
}
/**
* Fully populate the data by retrieving missing data.
*
* Depending on the original API call where this object is created, it may not contain everything.
*/
@Override
public synchronized void refresh() throws IOException {
root.retrieve().to(url, this);
}
}

View File

@@ -0,0 +1,76 @@
package org.kohsuke.github;
import org.apache.commons.codec.binary.Base64;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
/**
* Used to create/update content.
*
* <p>
* Call various methods to build up parameters, then call {@link #commit()} to make the change effective.
*
* @author Kohsuke Kawaguchi
* @see GHRepository#createContent()
*/
public final class GHContentBuilder {
private final GHRepository repo;
private final Requester req;
private String path;
GHContentBuilder(GHRepository repo) {
this.repo = repo;
this.req = new Requester(repo.root).method("PUT");
}
public GHContentBuilder path(String path) {
this.path = path;
req.with("path",path);
return this;
}
public GHContentBuilder branch(String branch) {
req.with("branch", branch);
return this;
}
/**
* Used when updating (but not creating a new content) to specify
* Thetblob SHA of the file being replaced.
*/
public GHContentBuilder sha(String sha) {
req.with("sha", sha);
return this;
}
public GHContentBuilder content(byte[] content) {
req.with("content", Base64.encodeBase64String(content));
return this;
}
public GHContentBuilder content(String content) {
try {
return content(content.getBytes("UTF-8"));
} catch (UnsupportedEncodingException x) {
throw new AssertionError();
}
}
public GHContentBuilder message(String commitMessage) {
req.with("message", commitMessage);
return this;
}
/**
* Commits a new content.
*/
public GHContentUpdateResponse commit() throws IOException {
GHContentUpdateResponse response = req.to(repo.getApiTailUrl("contents/" + path), GHContentUpdateResponse.class);
response.getContent().wrap(repo);
response.getCommit().wrapUp(repo);
return response;
}
}

View File

@@ -0,0 +1,20 @@
package org.kohsuke.github;
/**
* {@link GHContent} with license information.
*
* @author Kohsuke Kawaguchi
* @see <a href="https://developer.github.com/v3/licenses/#get-a-repositorys-license">documentation</a>
* @see GHRepository#getLicense()
*/
class GHContentWithLicense extends GHContent {
GHLicense license;
@Override
GHContentWithLicense wrap(GHRepository owner) {
super.wrap(owner);
if (license!=null)
license.wrap(owner.root);
return this;
}
}

View File

@@ -0,0 +1,138 @@
package org.kohsuke.github;
import java.io.IOException;
import java.net.URL;
/**
* Creates a repository
*
* @author Kohsuke Kawaguchi
*/
public class GHCreateRepositoryBuilder {
private final GitHub root;
protected final Requester builder;
private final String apiUrlTail;
/*package*/ GHCreateRepositoryBuilder(GitHub root, String apiUrlTail, String name) {
this.root = root;
this.apiUrlTail = apiUrlTail;
this.builder = new Requester(root);
this.builder.with("name",name);
}
public GHCreateRepositoryBuilder description(String description) {
this.builder.with("description",description);
return this;
}
public GHCreateRepositoryBuilder homepage(URL homepage) {
return homepage(homepage.toExternalForm());
}
public GHCreateRepositoryBuilder homepage(String homepage) {
this.builder.with("homepage",homepage);
return this;
}
/**
* Creates a private repository
*/
public GHCreateRepositoryBuilder private_(boolean b) {
this.builder.with("private",b);
return this;
}
/**
* Enables issue tracker
*/
public GHCreateRepositoryBuilder issues(boolean b) {
this.builder.with("has_issues",b);
return this;
}
/**
* Enables wiki
*/
public GHCreateRepositoryBuilder wiki(boolean b) {
this.builder.with("has_wiki",b);
return this;
}
/**
* Enables downloads
*/
public GHCreateRepositoryBuilder downloads(boolean b) {
this.builder.with("has_downloads",b);
return this;
}
/**
* If true, create an initial commit with empty README.
*/
public GHCreateRepositoryBuilder autoInit(boolean b) {
this.builder.with("auto_init",b);
return this;
}
/**
* Allow or disallow squash-merging pull requests.
*/
public GHCreateRepositoryBuilder allowSquashMerge(boolean b) {
this.builder.with("allow_squash_merge",b);
return this;
}
/**
* Allow or disallow merging pull requests with a merge commit.
*/
public GHCreateRepositoryBuilder allowMergeCommit(boolean b) {
this.builder.with("allow_merge_commit",b);
return this;
}
/**
* Allow or disallow rebase-merging pull requests.
*/
public GHCreateRepositoryBuilder allowRebaseMerge(boolean b) {
this.builder.with("allow_rebase_merge",b);
return this;
}
/**
* Creates a default .gitignore
*
* See https://developer.github.com/v3/repos/#create
*/
public GHCreateRepositoryBuilder gitignoreTemplate(String language) {
this.builder.with("gitignore_template",language);
return this;
}
/**
* Desired license template to apply
*
* See https://developer.github.com/v3/repos/#create
*/
public GHCreateRepositoryBuilder licenseTemplate(String license) {
this.builder.with("license_template",license);
return this;
}
/**
* The team that gets granted access to this repository. Only valid for creating a repository in
* an organization.
*/
public GHCreateRepositoryBuilder team(GHTeam team) {
if (team!=null)
this.builder.with("team_id",team.getId());
return this;
}
/**
* Creates a repository with all the parameters.
*/
public GHRepository create() throws IOException {
return builder.method("POST").to(apiUrlTail, GHRepository.class).wrap(root);
}
}

View File

@@ -1,17 +1,17 @@
package org.kohsuke.github;
import java.io.IOException;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import java.io.IOException;
public class GHDeployKey {
protected String url, key, title;
protected boolean verified;
protected int id;
protected long id;
private GHRepository owner;
public int getId() {
public long getId() {
return id;
}

View File

@@ -1,8 +1,15 @@
package org.kohsuke.github;
import java.io.IOException;
import java.net.URL;
/**
* Represents a deployment
*
* @see <a href="https://developer.github.com/v3/repos/deployments/">documentation</a>
* @see GHRepository#listDeployments(String, String, String, String)
* @see GHRepository#getDeployment(long)
*/
public class GHDeployment extends GHObject {
private GHRepository owner;
private GitHub root;
@@ -41,8 +48,8 @@ public class GHDeployment extends GHObject {
public String getEnvironment() {
return environment;
}
public GHUser getCreator() {
return creator;
public GHUser getCreator() throws IOException {
return root.intern(creator);
}
public String getRef() {
return ref;
@@ -58,4 +65,17 @@ public class GHDeployment extends GHObject {
public URL getHtmlUrl() {
return null;
}
public GHDeploymentStatusBuilder createStatus(GHDeploymentState state) {
return new GHDeploymentStatusBuilder(owner,id,state);
}
public PagedIterable<GHDeploymentStatus> listStatuses() {
return root.retrieve()
.asPagedIterable(
statuses_url,
GHDeploymentStatus[].class,
item -> item.wrap(owner) );
}
}

View File

@@ -1,18 +1,31 @@
package org.kohsuke.github;
import java.io.IOException;
import java.util.Locale;
/**
* Creates a new deployment status.
*
* @see
* GHDeployment#createStatus(GHDeploymentState)
*/
public class GHDeploymentStatusBuilder {
private final Requester builder;
private GHRepository repo;
private int deploymentId;
private long deploymentId;
/**
* @deprecated
* Use {@link GHDeployment#createStatus(GHDeploymentState)}
*/
public GHDeploymentStatusBuilder(GHRepository repo, int deploymentId, GHDeploymentState state) {
this(repo,(long)deploymentId,state);
}
/*package*/ GHDeploymentStatusBuilder(GHRepository repo, long deploymentId, GHDeploymentState state) {
this.repo = repo;
this.deploymentId = deploymentId;
this.builder = new Requester(repo.root);
this.builder.with("state",state.toString().toLowerCase(Locale.ENGLISH));
this.builder.with("state",state);
}
public GHDeploymentStatusBuilder description(String description) {
@@ -26,6 +39,6 @@ public class GHDeploymentStatusBuilder {
}
public GHDeploymentStatus create() throws IOException {
return builder.to(repo.getApiTailUrl("deployments")+"/"+deploymentId+"/statuses",GHDeploymentStatus.class).wrap(repo);
return builder.to(repo.getApiTailUrl("deployments/"+deploymentId+"/statuses"),GHDeploymentStatus.class).wrap(repo);
}
}

View File

@@ -0,0 +1,10 @@
package org.kohsuke.github;
/**
* Sort direction
*
* @author Kohsuke Kawaguchi
*/
public enum GHDirection {
ASC, DESC
}

View File

@@ -1,12 +1,13 @@
package org.kohsuke.github;
import java.util.Locale;
/**
* Hook event type.
*
* See http://developer.github.com/v3/events/types/
*
* @author Kohsuke Kawaguchi
* @see GHEventInfo
* @see <a href="https://developer.github.com/v3/activity/events/types/">Event type reference</a>
*/
public enum GHEvent {
COMMIT_COMMENT,
@@ -20,18 +21,46 @@ public enum GHEvent {
FORK_APPLY,
GIST,
GOLLUM,
INSTALLATION,
INSTALLATION_REPOSITORIES,
INTEGRATION_INSTALLATION_REPOSITORIES,
CHECK_SUITE,
ISSUE_COMMENT,
ISSUES,
LABEL,
MARKETPLACE_PURCHASE,
MEMBER,
MEMBERSHIP,
MILESTONE,
ORGANIZATION,
ORG_BLOCK,
PAGE_BUILD,
PROJECT_CARD,
PROJECT_COLUMN,
PROJECT,
PUBLIC,
PULL_REQUEST,
PULL_REQUEST_REVIEW,
PULL_REQUEST_REVIEW_COMMENT,
PUSH,
RELEASE,
REPOSITORY, // only valid for org hooks
STATUS,
TEAM,
TEAM_ADD,
WATCH,
PING
PING,
/**
* Special event type that means "every possible event"
*/
ALL;
/**
* Returns GitHub's internal representation of this event.
*/
String symbol() {
if (this==ALL) return "*";
return name().toLowerCase(Locale.ENGLISH);
}
}

View File

@@ -1,11 +1,11 @@
package org.kohsuke.github;
import java.io.IOException;
import java.util.Date;
import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.util.Date;
/**
* Represents an event.
*
@@ -18,6 +18,7 @@ public class GHEventInfo {
// we don't want to expose Jackson dependency to the user. This needs databinding
private ObjectNode payload;
private long id;
private String created_at;
private String type;
@@ -33,7 +34,7 @@ public class GHEventInfo {
"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, justification = "JSON API")
public static class GHEventRepository {
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
private int id;
private long id;
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
private String url; // repository API URL
private String name; // owner/repo
@@ -54,6 +55,10 @@ public class GHEventInfo {
return this;
}
public long getId() {
return id;
}
public Date getCreatedAt() {
return GitHub.parseDate(created_at);
}

View File

@@ -1,6 +1,9 @@
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.Reader;
import java.util.List;
@@ -14,11 +17,28 @@ import java.util.List;
public abstract class GHEventPayload {
protected GitHub root;
private GHUser sender;
/*package*/ GHEventPayload() {
}
/**
* Gets the sender or {@code null} if accessed via the events API.
* @return the sender or {@code null} if accessed via the events API.
*/
public GHUser getSender() {
return sender;
}
public void setSender(GHUser sender) {
this.sender = sender;
}
/*package*/ void wrapUp(GitHub root) {
this.root = root;
if (sender != null) {
sender.wrapUp(root);
}
}
/**
@@ -58,13 +78,147 @@ public abstract class GHEventPayload {
throw new IllegalStateException("Expected pull_request payload, but got something else. Maybe we've got another type of event?");
if (repository!=null) {
repository.wrap(root);
pull_request.wrap(repository);
pull_request.wrapUp(repository);
} else {
pull_request.wrapUp(root);
}
}
}
/**
* A review was added to a pull request
*
* @see <a href="https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent">authoritative source</a>
*/
public static class PullRequestReview extends GHEventPayload {
private String action;
private GHPullRequestReview review;
private GHPullRequest pull_request;
private GHRepository repository;
public String getAction() {
return action;
}
public GHPullRequestReview getReview() {
return review;
}
public GHPullRequest getPullRequest() {
return pull_request;
}
public GHRepository getRepository() {
return repository;
}
@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
if (review==null)
throw new IllegalStateException("Expected pull_request_review payload, but got something else. Maybe we've got another type of event?");
review.wrapUp(pull_request);
if (repository!=null) {
repository.wrap(root);
pull_request.wrapUp(repository);
} else {
pull_request.wrapUp(root);
}
}
}
/**
* A review comment was added to a pull request
*
* @see <a href="https://developer.github.com/v3/activity/events/types/#pullrequestreviewcommentevent">authoritative source</a>
*/
public static class PullRequestReviewComment extends GHEventPayload {
private String action;
private GHPullRequestReviewComment comment;
private GHPullRequest pull_request;
private GHRepository repository;
public String getAction() {
return action;
}
public GHPullRequestReviewComment getComment() {
return comment;
}
public GHPullRequest getPullRequest() {
return pull_request;
}
public GHRepository getRepository() {
return repository;
}
@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
if (comment==null)
throw new IllegalStateException("Expected pull_request_review_comment payload, but got something else. Maybe we've got another type of event?");
comment.wrapUp(pull_request);
if (repository!=null) {
repository.wrap(root);
pull_request.wrapUp(repository);
} else {
pull_request.wrapUp(root);
}
}
}
/**
* A Issue has been assigned, unassigned, labeled, unlabeled, opened, edited, milestoned, demilestoned, closed, or reopened.
*
* @see <a href="http://developer.github.com/v3/activity/events/types/#issueevent">authoritative source</a>
*/
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" },
justification = "Constructed by JSON deserialization")
public static class Issue extends GHEventPayload {
private String action;
private GHIssue issue;
private GHRepository repository;
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization")
public String getAction() {
return action;
}
public GHIssue getIssue() {
return issue;
}
public void setIssue(GHIssue issue) {
this.issue = issue;
}
public GHRepository getRepository() {
return repository;
}
public void setRepository(GHRepository repository) {
this.repository = repository;
}
@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
if (repository != null) {
repository.wrap(root);
issue.wrap(repository);
} else {
issue.wrap(root);
}
}
}
/**
* A comment was added to an issue
*
@@ -120,17 +274,340 @@ public abstract class GHEventPayload {
}
}
/**
* A comment was added to a commit
*
* @see <a href="http://developer.github.com/v3/activity/events/types/#commitcommentevent">authoritative source</a>
*/
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" },
justification = "Constructed by JSON deserialization")
public static class CommitComment extends GHEventPayload {
private String action;
private GHCommitComment comment;
private GHRepository repository;
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization")
public String getAction() {
return action;
}
public GHCommitComment getComment() {
return comment;
}
public void setComment(GHCommitComment comment) {
this.comment = comment;
}
public GHRepository getRepository() {
return repository;
}
public void setRepository(GHRepository repository) {
this.repository = repository;
}
@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
if (repository != null) {
repository.wrap(root);
comment.wrap(repository);
}
}
}
/**
* A repository, branch, or tag was created
*
* @see <a href="http://developer.github.com/v3/activity/events/types/#createevent">authoritative source</a>
*/
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" },
justification = "Constructed by JSON deserialization")
public static class Create extends GHEventPayload {
private String ref;
@JsonProperty("ref_type")
private String refType;
@JsonProperty("master_branch")
private String masterBranch;
private String description;
private GHRepository repository;
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization")
public String getRef() {
return ref;
}
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization")
public String getRefType() {
return refType;
}
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization")
public String getMasterBranch() {
return masterBranch;
}
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization")
public String getDescription() {
return description;
}
public GHRepository getRepository() {
return repository;
}
public void setRepository(GHRepository repository) {
this.repository = repository;
}
@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
if (repository != null) {
repository.wrap(root);
}
}
}
/**
* A branch, or tag was deleted
*
* @see <a href="http://developer.github.com/v3/activity/events/types/#deleteevent">authoritative source</a>
*/
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" },
justification = "Constructed by JSON deserialization")
public static class Delete extends GHEventPayload {
private String ref;
@JsonProperty("ref_type")
private String refType;
private GHRepository repository;
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization")
public String getRef() {
return ref;
}
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization")
public String getRefType() {
return refType;
}
public GHRepository getRepository() {
return repository;
}
public void setRepository(GHRepository repository) {
this.repository = repository;
}
@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
if (repository != null) {
repository.wrap(root);
}
}
}
/**
* A deployment
*
* @see <a href="http://developer.github.com/v3/activity/events/types/#deploymentevent">authoritative source</a>
*/
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" },
justification = "Constructed by JSON deserialization")
public static class Deployment extends GHEventPayload {
private GHDeployment deployment;
private GHRepository repository;
public GHDeployment getDeployment() {
return deployment;
}
public void setDeployment(GHDeployment deployment) {
this.deployment = deployment;
}
public GHRepository getRepository() {
return repository;
}
public void setRepository(GHRepository repository) {
this.repository = repository;
}
@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
if (repository != null) {
repository.wrap(root);
deployment.wrap(repository);
}
}
}
/**
* A deployment
*
* @see <a href="http://developer.github.com/v3/activity/events/types/#deploymentstatusevent">authoritative source</a>
*/
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" },
justification = "Constructed by JSON deserialization")
public static class DeploymentStatus extends GHEventPayload {
@JsonProperty("deployment_status")
private GHDeploymentStatus deploymentStatus;
private GHDeployment deployment;
private GHRepository repository;
public GHDeploymentStatus getDeploymentStatus() {
return deploymentStatus;
}
public void setDeploymentStatus(GHDeploymentStatus deploymentStatus) {
this.deploymentStatus = deploymentStatus;
}
public GHDeployment getDeployment() {
return deployment;
}
public void setDeployment(GHDeployment deployment) {
this.deployment = deployment;
}
public GHRepository getRepository() {
return repository;
}
public void setRepository(GHRepository repository) {
this.repository = repository;
}
@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
if (repository != null) {
repository.wrap(root);
deployment.wrap(repository);
deploymentStatus.wrap(repository);
}
}
}
/**
* A user forked a repository
*
* @see <a href="http://developer.github.com/v3/activity/events/types/#forkevent">authoritative source</a>
*/
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" },
justification = "Constructed by JSON deserialization")
public static class Fork extends GHEventPayload {
private GHRepository forkee;
private GHRepository repository;
public GHRepository getForkee() {
return forkee;
}
public void setForkee(GHRepository forkee) {
this.forkee = forkee;
}
public GHRepository getRepository() {
return repository;
}
public void setRepository(GHRepository repository) {
this.repository = repository;
}
@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
forkee.wrap(root);
if (repository != null) {
repository.wrap(root);
}
}
}
/**
* A ping.
*/
public static class Ping extends GHEventPayload {
private GHRepository repository;
private GHOrganization organization;
public void setRepository(GHRepository repository) {
this.repository = repository;
}
public GHRepository getRepository() {
return repository;
}
public GHOrganization getOrganization() {
return organization;
}
public void setOrganization(GHOrganization organization) {
this.organization = organization;
}
@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
if (repository!=null)
repository.wrap(root);
if (organization != null) {
organization.wrapUp(root);
}
}
}
/**
* A repository was made public.
*
* @see <a href="http://developer.github.com/v3/activity/events/types/#publicevent">authoritative source</a>
*/
public static class Public extends GHEventPayload {
private GHRepository repository;
public void setRepository(GHRepository repository) {
this.repository = repository;
}
public GHRepository getRepository() {
return repository;
}
@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
if (repository!=null)
repository.wrap(root);
}
}
/**
* A commit was pushed.
*
* @see <a href="http://developer.github.com/v3/activity/events/types/#pushevent">authoritative source</a>
*/
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD", "UUF_UNUSED_FIELD"},
justification = "Constructed by JSON deserialization")
public static class Push extends GHEventPayload {
private String head, before;
private boolean created, deleted, forced;
private String ref;
private int size;
private List<PushCommit> commits;
private GHRepository repository;
private Pusher pusher;
/**
* The SHA of the HEAD commit on the repository
@@ -147,6 +624,11 @@ public abstract class GHEventPayload {
return before;
}
@JsonSetter // alias
private void setAfter(String after) {
head = after;
}
/**
* The full Git ref that was pushed. Example: “refs/heads/master”
*/
@@ -162,6 +644,18 @@ public abstract class GHEventPayload {
return size;
}
public boolean isCreated() {
return created;
}
public boolean isDeleted() {
return deleted;
}
public boolean isForced() {
return forced;
}
/**
* The list of pushed commits.
*/
@@ -173,6 +667,14 @@ public abstract class GHEventPayload {
return repository;
}
public Pusher getPusher() {
return pusher;
}
public void setPusher(Pusher pusher) {
this.pusher = pusher;
}
@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
@@ -180,18 +682,44 @@ public abstract class GHEventPayload {
repository.wrap(root);
}
public static class Pusher {
private String name, email;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
/**
* Commit in a push
*/
public static class PushCommit {
private GitUser author;
private GitUser committer;
private String url, sha, message;
private boolean distinct;
private List<String> added, removed, modified;
public GitUser getAuthor() {
return author;
}
public GitUser getCommitter() {
return committer;
}
/**
* Points to the commit API resource.
*/
@@ -203,6 +731,11 @@ public abstract class GHEventPayload {
return sha;
}
@JsonSetter
private void setId(String id) {
sha = id;
}
public String getMessage() {
return message;
}
@@ -213,6 +746,103 @@ public abstract class GHEventPayload {
public boolean isDistinct() {
return distinct;
}
public List<String> getAdded() {
return added;
}
public List<String> getRemoved() {
return removed;
}
public List<String> getModified() {
return modified;
}
}
}
/**
* A release was added to the repo
*
* @see <a href="http://developer.github.com/v3/activity/events/types/#releaseevent">authoritative source</a>
*/
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" },
justification = "Constructed by JSON deserialization")
public static class Release extends GHEventPayload {
private String action;
private GHRelease release;
private GHRepository repository;
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization")
public String getAction() {
return action;
}
public GHRelease getRelease() {
return release;
}
public void setRelease(GHRelease release) {
this.release = release;
}
public GHRepository getRepository() {
return repository;
}
public void setRepository(GHRepository repository) {
this.repository = repository;
}
@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
if (repository != null) {
repository.wrap(root);
}
}
}
/**
* A repository was created, deleted, made public, or made private.
*
* @see <a href="http://developer.github.com/v3/activity/events/types/#repositoryevent">authoritative source</a>
*/
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD"},
justification = "Constructed by JSON deserialization")
public static class Repository extends GHEventPayload {
private String action;
private GHRepository repository;
private GHOrganization organization;
public String getAction() {
return action;
}
public void setRepository(GHRepository repository) {
this.repository = repository;
}
public GHRepository getRepository() {
return repository;
}
public GHOrganization getOrganization() {
return organization;
}
public void setOrganization(GHOrganization organization) {
this.organization = organization;
}
@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
repository.wrap(root);
if (organization != null) {
organization.wrapUp(root);
}
}
}
}

View File

@@ -0,0 +1,34 @@
package org.kohsuke.github;
import javax.annotation.CheckForNull;
import java.io.FileNotFoundException;
import java.net.HttpURLConnection;
import java.util.List;
import java.util.Map;
/**
* Request/responce contains useful metadata.
* Custom exception allows store info for next diagnostics.
*
* @author Kanstantsin Shautsou
*/
public class GHFileNotFoundException extends FileNotFoundException {
protected Map<String, List<String>> responseHeaderFields;
public GHFileNotFoundException() {
}
public GHFileNotFoundException(String s) {
super(s);
}
@CheckForNull
public Map<String, List<String>> getResponseHeaderFields() {
return responseHeaderFields;
}
GHFileNotFoundException withResponseHeaderFields(HttpURLConnection urlConnection) {
this.responseHeaderFields = urlConnection.getHeaderFields();
return this;
}
}

View File

@@ -1,6 +1,7 @@
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.net.URL;
@@ -38,8 +39,8 @@ public class GHGist extends GHObject {
/**
* User that owns this Gist.
*/
public GHUser getOwner() {
return owner;
public GHUser getOwner() throws IOException {
return root.intern(owner);
}
public String getForksUrl() {
@@ -103,7 +104,7 @@ public class GHGist extends GHObject {
* Used when caller obtains {@link GHGist} without knowing its owner.
* A partially constructed owner object is interned.
*/
/*package*/ GHGist wrapUp(GitHub root) throws IOException {
/*package*/ GHGist wrapUp(GitHub root) {
this.owner = root.getUser(owner);
this.root = root;
wrapUp();
@@ -115,8 +116,13 @@ public class GHGist extends GHObject {
e.getValue().fileName = e.getKey();
}
}
String getApiTailUrl(String tail) {
return "/gists/" + id + '/' + tail;
String result = "/gists/" + id;
if (!StringUtils.isBlank(tail)) {
result += StringUtils.prependIfMissing(tail, "/");
}
return result;
}
public void star() throws IOException {
@@ -139,21 +145,11 @@ public class GHGist extends GHObject {
}
public PagedIterable<GHGist> listForks() {
return new PagedIterable<GHGist>() {
public PagedIterator<GHGist> iterator() {
return new PagedIterator<GHGist>(root.retrieve().asIterator(getApiTailUrl("forks"), GHGist[].class)) {
@Override
protected void wrapUp(GHGist[] page) {
try {
for (GHGist c : page)
c.wrapUp(root);
} catch (IOException e) {
throw new Error(e);
}
}
};
}
};
return root.retrieve()
.asPagedIterable(
getApiTailUrl("forks"),
GHGist[].class,
item -> item.wrapUp(root) );
}
/**
@@ -163,6 +159,13 @@ public class GHGist extends GHObject {
new Requester(root).method("DELETE").to("/gists/" + id);
}
/**
* Updates this gist via a builder.
*/
public GHGistUpdater update() throws IOException {
return new GHGistUpdater(this);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -176,4 +179,10 @@ public class GHGist extends GHObject {
public int hashCode() {
return id.hashCode();
}
GHGist wrap(GHUser owner) {
this.owner = owner;
this.root = owner.root;
return this;
}
}

View File

@@ -0,0 +1,60 @@
package org.kohsuke.github;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashMap;
/**
* Builder pattern for updating a Gist.
*
* @author Martin van Zijl
*/
public class GHGistUpdater {
private final GHGist base;
private final Requester builder;
LinkedHashMap<String,Object> files;
GHGistUpdater(GHGist base) {
this.base = base;
this.builder = new Requester(base.root);
files = new LinkedHashMap<>();
}
public GHGistUpdater addFile(String fileName, String content) throws IOException {
updateFile(fileName, content);
return this;
}
// // This method does not work.
// public GHGistUpdater deleteFile(String fileName) throws IOException {
// files.put(fileName, Collections.singletonMap("filename", null));
// return this;
// }
public GHGistUpdater renameFile(String fileName, String newFileName) throws IOException
{
files.put(fileName, Collections.singletonMap("filename", newFileName));
return this;
}
public GHGistUpdater updateFile(String fileName, String content) throws IOException {
files.put(fileName, Collections.singletonMap("content", content));
return this;
}
public GHGistUpdater description(String desc) {
builder.with("description",desc);
return this;
}
/**
* Updates the Gist based on the parameters specified thus far.
*/
public GHGist update() throws IOException {
builder._with("files", files);
return builder
.method("PATCH")
.to(base.getApiTailUrl(""), GHGist.class).wrap(base.owner);
}
}

View File

@@ -1,6 +1,7 @@
package org.kohsuke.github;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
@@ -26,8 +27,10 @@ public abstract class GHHook extends GHObject {
public EnumSet<GHEvent> getEvents() {
EnumSet<GHEvent> s = EnumSet.noneOf(GHEvent.class);
for (String e : events)
s.add(Enum.valueOf(GHEvent.class,e.toUpperCase(Locale.ENGLISH)));
for (String e : events) {
if (e.equals("*")) s.add(GHEvent.ALL);
else s.add(Enum.valueOf(GHEvent.class, e.toUpperCase(Locale.ENGLISH)));
}
return s;
}
@@ -39,6 +42,13 @@ public abstract class GHHook extends GHObject {
return Collections.unmodifiableMap(config);
}
/**
* @see <a href="https://developer.github.com/v3/repos/hooks/#ping-a-hook">Ping hook</a>
*/
public void ping() throws IOException {
new Requester(getRoot()).method("POST").to(getApiRoute() + "/pings");
}
/**
* Deletes this hook.
*/

View File

@@ -5,7 +5,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
@@ -39,7 +38,7 @@ class GHHooks {
if (events!=null) {
ea = new ArrayList<String>();
for (GHEvent e : events)
ea.add(e.name().toLowerCase(Locale.ENGLISH));
ea.add(e.symbol());
}
GHHook hook = new Requester(root)

View File

@@ -0,0 +1,34 @@
package org.kohsuke.github;
import javax.annotation.CheckForNull;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.List;
import java.util.Map;
/**
* Request/responce contains useful metadata.
* Custom exception allows store info for next diagnostics.
*
* @author Kanstantsin Shautsou
*/
public class GHIOException extends IOException {
protected Map<String, List<String>> responseHeaderFields;
public GHIOException() {
}
public GHIOException(String message) {
super(message);
}
@CheckForNull
public Map<String, List<String>> getResponseHeaderFields() {
return responseHeaderFields;
}
GHIOException withResponseHeaderFields(HttpURLConnection urlConnection) {
this.responseHeaderFields = urlConnection.getHeaderFields();
return this;
}
}

View File

@@ -0,0 +1,46 @@
package org.kohsuke.github;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.net.URL;
/**
* @see GitHub#getMyInvitations()
* @see GHRepository#listInvitations()
*/
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD", "UUF_UNUSED_FIELD"}, justification = "JSON API")
public class GHInvitation extends GHObject {
/*package almost final*/ GitHub root;
private int id;
private GHRepository repository;
private GHUser invitee, inviter;
private String permissions;
private String html_url;
/*package*/ GHInvitation wrapUp(GitHub root) {
this.root = root;
return this;
}
/**
* Accept a repository invitation.
*/
public void accept() throws IOException {
root.retrieve().method("PATCH").to("/user/repository_invitations/" + id);
}
/**
* Decline a repository invitation.
*/
public void decline() throws IOException {
root.retrieve().method("DELETE").to("/user/repository_invitations/" + id);
}
@Override
public URL getHtmlUrl() {
return GitHub.parseURL(html_url);
}
}

View File

@@ -24,16 +24,21 @@
package org.kohsuke.github;
import static org.kohsuke.github.Previews.SQUIRREL_GIRL;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
/**
* Represents an issue on GitHub.
@@ -44,16 +49,20 @@ import java.util.Locale;
* @see GitHub#searchIssues()
* @see GHIssueSearchBuilder
*/
public class GHIssue extends GHObject {
public class GHIssue extends GHObject implements Reactable{
private static final String ASSIGNEES = "assignees";
GitHub root;
GHRepository owner;
// API v3
protected GHUser assignee;
protected GHUser assignee; // not sure what this field is now that 'assignees' exist
protected GHUser[] assignees;
protected String state;
protected int number;
protected String closed_at;
protected int comments;
@SkipFromToString
protected String body;
// for backward compatibility with < 1.63, this collection needs to hold instances of Label, not GHLabel
protected List<Label> labels;
@@ -62,6 +71,7 @@ public class GHIssue extends GHObject {
protected GHIssue.PullRequest pull_request;
protected GHMilestone milestone;
protected GHUser closed_by;
protected boolean locked;
/**
* @deprecated use {@link GHLabel}
@@ -78,6 +88,7 @@ public class GHIssue extends GHObject {
/*package*/ GHIssue wrap(GitHub root) {
this.root = root;
if(assignee != null) assignee.wrapUp(root);
if(assignees!=null) GHUser.wrap(assignees,root);
if(user != null) user.wrapUp(root);
if(closed_by != null) closed_by.wrapUp(root);
return this;
@@ -122,6 +133,10 @@ public class GHIssue extends GHObject {
return title;
}
public boolean isLocked() {
return locked;
}
public GHIssueState getState() {
return Enum.valueOf(GHIssueState.class, state.toUpperCase(Locale.ENGLISH));
}
@@ -141,6 +156,14 @@ public class GHIssue extends GHObject {
return GitHub.parseURL(url);
}
public void lock() throws IOException {
new Requester(root).method("PUT").to(getApiRoute()+"/lock");
}
public void unlock() throws IOException {
new Requester(root).method("PUT").to(getApiRoute()+"/lock");
}
/**
* Updates the issue by adding a comment.
*
@@ -183,14 +206,79 @@ public class GHIssue extends GHObject {
edit("body",body);
}
public void setMilestone(GHMilestone milestone) throws IOException {
edit("milestone",milestone.getNumber());
}
public void assignTo(GHUser user) throws IOException {
editIssue("assignee", user.getLogin());
setAssignees(user);
}
public void setLabels(String... labels) throws IOException {
editIssue("labels",labels);
}
/**
* Adds labels to the issue.
*
* @param names Names of the label
*/
public void addLabels(String... names) throws IOException {
_addLabels(Arrays.asList(names));
}
public void addLabels(GHLabel... labels) throws IOException {
addLabels(Arrays.asList(labels));
}
public void addLabels(Collection<GHLabel> labels) throws IOException {
_addLabels(GHLabel.toNames(labels));
}
private void _addLabels(Collection<String> names) throws IOException {
List<String> newLabels = new ArrayList<String>();
for (GHLabel label : getLabels()) {
newLabels.add(label.getName());
}
for (String name : names) {
if (!newLabels.contains(name)) {
newLabels.add(name);
}
}
setLabels(newLabels.toArray(new String[0]));
}
/**
* Remove a given label by name from this issue.
*/
public void removeLabels(String... names) throws IOException {
_removeLabels(Arrays.asList(names));
}
/**
* @see #removeLabels(String...)
*/
public void removeLabels(GHLabel... labels) throws IOException {
removeLabels(Arrays.asList(labels));
}
public void removeLabels(Collection<GHLabel> labels) throws IOException {
_removeLabels(GHLabel.toNames(labels));
}
private void _removeLabels(Collection<String> names) throws IOException {
List<String> newLabels = new ArrayList<String>();
for (GHLabel l : getLabels()) {
if (!names.contains(l.getName())) {
newLabels.add(l.getName());
}
}
setLabels(newLabels.toArray(new String[0]));
}
/**
* Obtains all the comments associated with this issue.
*
@@ -204,16 +292,52 @@ public class GHIssue extends GHObject {
* Obtains all the comments associated with this issue.
*/
public PagedIterable<GHIssueComment> listComments() throws IOException {
return new PagedIterable<GHIssueComment>() {
public PagedIterator<GHIssueComment> iterator() {
return new PagedIterator<GHIssueComment>(root.retrieve().asIterator(getIssuesApiRoute() + "/comments", GHIssueComment[].class)) {
protected void wrapUp(GHIssueComment[] page) {
for (GHIssueComment c : page)
c.wrapUp(GHIssue.this);
}
};
}
};
return root.retrieve()
.asPagedIterable(
getIssuesApiRoute() + "/comments",
GHIssueComment[].class,
item -> item.wrapUp(GHIssue.this) );
}
@Preview @Deprecated
public GHReaction createReaction(ReactionContent content) throws IOException {
return new Requester(owner.root)
.withPreview(SQUIRREL_GIRL)
.with("content", content.getContent())
.to(getApiRoute()+"/reactions", GHReaction.class).wrap(root);
}
@Preview @Deprecated
public PagedIterable<GHReaction> listReactions() {
return owner.root.retrieve().withPreview(SQUIRREL_GIRL)
.asPagedIterable(
getApiRoute()+"/reactions",
GHReaction[].class,
item -> item.wrap(owner.root) );
}
public void addAssignees(GHUser... assignees) throws IOException {
addAssignees(Arrays.asList(assignees));
}
public void addAssignees(Collection<GHUser> assignees) throws IOException {
root.retrieve().method("POST").withLogins(ASSIGNEES,assignees).to(getIssuesApiRoute()+"/assignees",this);
}
public void setAssignees(GHUser... assignees) throws IOException {
setAssignees(Arrays.asList(assignees));
}
public void setAssignees(Collection<GHUser> assignees) throws IOException {
new Requester(root).withLogins(ASSIGNEES, assignees).method("PATCH").to(getIssuesApiRoute());
}
public void removeAssignees(GHUser... assignees) throws IOException {
removeAssignees(Arrays.asList(assignees));
}
public void removeAssignees(Collection<GHUser> assignees) throws IOException {
root.retrieve().method("DELETE").withLogins(ASSIGNEES,assignees).inBody().to(getIssuesApiRoute()+"/assignees",this);
}
protected String getApiRoute() {
@@ -224,15 +348,19 @@ public class GHIssue extends GHObject {
return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/issues/"+number;
}
public GHUser getAssignee() {
return assignee;
public GHUser getAssignee() throws IOException {
return root.intern(assignee);
}
public List<GHUser> getAssignees() {
return Collections.unmodifiableList(Arrays.asList(assignees));
}
/**
* User who submitted the issue.
*/
public GHUser getUser() {
return user;
public GHUser getUser() throws IOException {
return root.intern(user);
}
/**
@@ -243,12 +371,16 @@ public class GHIssue extends GHObject {
* even for an issue that's already closed. See
* https://github.com/kohsuke/github-api/issues/60.
*/
public GHUser getClosedBy() {
public GHUser getClosedBy() throws IOException {
if(!"closed".equals(state)) return null;
if(closed_by != null) return closed_by;
//TODO closed_by = owner.getIssue(number).getClosed_by();
return closed_by;
//TODO
/*
if (closed_by==null) {
closed_by = owner.getIssue(number).getClosed_by();
}
*/
return root.intern(closed_by);
}
public int getCommentsCount(){
@@ -287,4 +419,15 @@ public class GHIssue extends GHObject {
return GitHub.parseURL(html_url);
}
}
/**
* Lists events for this issue.
* See https://developer.github.com/v3/issues/events/
*/
public PagedIterable<GHIssueEvent> listEvents() throws IOException {
return root.retrieve().asPagedIterable(
owner.getApiTailUrl(String.format("/issues/%s/events", number)),
GHIssueEvent[].class,
item -> item.wrapUp(GHIssue.this) );
}
}

View File

@@ -11,6 +11,7 @@ public class GHIssueBuilder {
private final GHRepository repo;
private final Requester builder;
private List<String> labels = new ArrayList<String>();
private List<String> assignees = new ArrayList<String>();
GHIssueBuilder(GHRepository repo, String title) {
this.repo = repo;
@@ -28,13 +29,13 @@ public class GHIssueBuilder {
public GHIssueBuilder assignee(GHUser user) {
if (user!=null)
builder.with("assignee",user.getLogin());
assignees.add(user.getLogin());
return this;
}
public GHIssueBuilder assignee(String user) {
if (user!=null)
builder.with("assignee",user);
assignees.add(user);
return this;
}
@@ -54,6 +55,6 @@ public class GHIssueBuilder {
* Creates a new issue.
*/
public GHIssue create() throws IOException {
return builder.with("labels",labels).to(repo.getApiTailUrl("issues"),GHIssue.class).wrap(repo);
return builder.with("labels",labels).with("assignees",assignees).to(repo.getApiTailUrl("issues"),GHIssue.class).wrap(repo);
}
}

View File

@@ -26,16 +26,20 @@ package org.kohsuke.github;
import java.io.IOException;
import java.net.URL;
import static org.kohsuke.github.Previews.*;
/**
* Comment to the issue
*
* @author Kohsuke Kawaguchi
* @see GHIssue#comment(String)
* @see GHIssue#listComments()
*/
public class GHIssueComment extends GHObject {
public class GHIssueComment extends GHObject implements Reactable {
GHIssue owner;
private String body, gravatar_id;
private GHUser user;
private String body, gravatar_id, html_url, author_association;
private GHUser user; // not fully populated. beware.
/*package*/ GHIssueComment wrapUp(GHIssue owner) {
this.owner = owner;
@@ -68,15 +72,16 @@ public class GHIssueComment extends GHObject {
* Gets the user who posted this comment.
*/
public GHUser getUser() throws IOException {
return owner.root.getUser(user.getLogin());
return owner == null || owner.root.isOffline() ? user : owner.root.getUser(user.getLogin());
}
/**
* @deprecated This object has no HTML URL.
*/
@Override
public URL getHtmlUrl() {
return null;
return GitHub.parseURL(html_url);
}
public GHCommentAuthorAssociation getAuthorAssociation() {
return GHCommentAuthorAssociation.valueOf(author_association);
}
/**
@@ -93,7 +98,25 @@ public class GHIssueComment extends GHObject {
public void delete() throws IOException {
new Requester(owner.root).method("DELETE").to(getApiRoute());
}
@Preview @Deprecated
public GHReaction createReaction(ReactionContent content) throws IOException {
return new Requester(owner.root)
.withPreview(SQUIRREL_GIRL)
.with("content", content.getContent())
.to(getApiRoute()+"/reactions", GHReaction.class).wrap(owner.root);
}
@Preview @Deprecated
public PagedIterable<GHReaction> listReactions() {
return owner.root.retrieve()
.withPreview(SQUIRREL_GIRL)
.asPagedIterable(
getApiRoute()+"/reactions",
GHReaction[].class,
item -> item.wrap(owner.root) );
}
private String getApiRoute() {
return "/repos/"+owner.getRepository().getOwnerName()+"/"+owner.getRepository().getName()+"/issues/comments/" + id;
}

View File

@@ -0,0 +1,81 @@
package org.kohsuke.github;
import java.util.Date;
/**
* @author Martin van Zijl
*/
public class GHIssueEvent {
private GitHub root;
private long id;
private String node_id;
private String url;
private GHUser actor;
private String event;
private String commit_id;
private String commit_url;
private String created_at;
private GHIssue issue;
public long getId() {
return id;
}
public String getNodeId() {
return node_id;
}
public String getUrl() {
return url;
}
public GHUser getActor() {
return actor;
}
public String getEvent() {
return event;
}
public String getCommitId() {
return commit_id;
}
public String getCommitUrl() {
return commit_url;
}
public Date getCreatedAt() {
return GitHub.parseDate(created_at);
}
public GitHub getRoot() {
return root;
}
public GHIssue getIssue() {
return issue;
}
GHIssueEvent wrapUp(GitHub root) {
this.root = root;
return this;
}
GHIssueEvent wrapUp(GHIssue parent) {
this.issue = parent;
this.root = parent.root;
return this;
}
@Override
public String toString() {
return String.format("Issue %d was %s by %s on %s",
getIssue().getNumber(),
getEvent(),
getActor().getLogin(),
getCreatedAt().toString());
}
}

View File

@@ -1,7 +1,5 @@
package org.kohsuke.github;
import java.util.Locale;
/**
* Search issues.
*
@@ -41,8 +39,13 @@ public class GHIssueSearchBuilder extends GHSearchBuilder<GHIssue> {
return q("is:merged");
}
public GHIssueSearchBuilder order(GHDirection v) {
req.with("order",v);
return this;
}
public GHIssueSearchBuilder sort(Sort sort) {
req.with("sort",sort.toString().toLowerCase(Locale.ENGLISH));
req.with("sort",sort);
return this;
}

View File

@@ -24,7 +24,11 @@
package org.kohsuke.github;
/**
* @see GHPullRequestQueryBuilder#state(GHIssueState)
*/
public enum GHIssueState {
OPEN,
CLOSED
CLOSED,
ALL
}

View File

@@ -1,7 +1,7 @@
package org.kohsuke.github;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
/**
* SSH public key.

View File

@@ -1,14 +1,19 @@
package org.kohsuke.github;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import static org.kohsuke.github.Previews.SYMMETRA;
/**
* @author Kohsuke Kawaguchi
* @see GHIssue#getLabels()
* @see GHRepository#listLabels()
*/
public class GHLabel {
private String url, name, color;
private String url, name, color, description;
private GHRepository repo;
public String getUrl() {
@@ -26,6 +31,14 @@ public class GHLabel {
return color;
}
/**
* Purpose of Label
*/
@Preview @Deprecated
public String getDescription() {
return description;
}
/*package*/ GHLabel wrapUp(GHRepository repo) {
this.repo = repo;
return this;
@@ -34,4 +47,55 @@ public class GHLabel {
public void delete() throws IOException {
repo.root.retrieve().method("DELETE").to(url);
}
/**
* @param newColor
* 6-letter hex color code, like "f29513"
*/
public void setColor(String newColor) throws IOException {
repo.root.retrieve().method("PATCH")
.withPreview(SYMMETRA)
.with("name", name)
.with("color", newColor)
.with("description", description)
.to(url);
}
/**
* @param newDescription
* Description of label
*/
@Preview @Deprecated
public void setDescription(String newDescription) throws IOException {
repo.root.retrieve().method("PATCH")
.withPreview(SYMMETRA)
.with("name", name)
.with("color", color)
.with("description", newDescription)
.to(url);
}
/*package*/ static Collection<String> toNames(Collection<GHLabel> labels) {
List<String> r = new ArrayList<String>();
for (GHLabel l : labels) {
r.add(l.getName());
}
return r;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final GHLabel ghLabel = (GHLabel) o;
return Objects.equals(url, ghLabel.url) &&
Objects.equals(name, ghLabel.name) &&
Objects.equals(color, ghLabel.color) &&
Objects.equals(repo, ghLabel.repo);
}
@Override
public int hashCode() {
return Objects.hash(url, name, color, repo);
}
}

View File

@@ -0,0 +1,164 @@
/*
* The MIT License
*
* Copyright (c) 2016, Duncan Dickinson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.kohsuke.github;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
/**
* The GitHub Preview API's license information
* <p>
*
* @author Duncan Dickinson
* @see GitHub#getLicense(String)
* @see GHRepository#getLicense()
* @see <a href="https://developer.github.com/v3/licenses/">https://developer.github.com/v3/licenses/</a>
*/
@SuppressWarnings({"UnusedDeclaration"})
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
public class GHLicense extends GHObject {
@SuppressFBWarnings("IS2_INCONSISTENT_SYNC") // root is set before the object is returned to the app
/*package almost final*/ GitHub root;
// these fields are always present, even in the short form
protected String key, name;
// the rest is only after populated
protected Boolean featured;
protected String html_url, description, category, implementation, body;
protected List<String> required = new ArrayList<String>();
protected List<String> permitted = new ArrayList<String>();
protected List<String> forbidden = new ArrayList<String>();
/**
* @return a mnemonic for the license
*/
public String getKey() {
return key;
}
/**
* @return the license name
*/
public String getName() {
return name;
}
/**
* @return API URL of this object.
*/
@WithBridgeMethods(value = String.class, adapterMethod = "urlToString")
public URL getUrl() {
return GitHub.parseURL(url);
}
/**
* Featured licenses are bold in the new repository drop-down
*
* @return True if the license is featured, false otherwise
*/
public Boolean isFeatured() throws IOException {
populate();
return featured;
}
public URL getHtmlUrl() throws IOException {
populate();
return GitHub.parseURL(html_url);
}
public String getDescription() throws IOException {
populate();
return description;
}
public String getCategory() throws IOException {
populate();
return category;
}
public String getImplementation() throws IOException {
populate();
return implementation;
}
public List<String> getRequired() throws IOException {
populate();
return required;
}
public List<String> getPermitted() throws IOException {
populate();
return permitted;
}
public List<String> getForbidden() throws IOException {
populate();
return forbidden;
}
public String getBody() throws IOException {
populate();
return body;
}
/**
* Fully populate the data by retrieving missing data.
*
* Depending on the original API call where this object is created, it may not contain everything.
*/
protected synchronized void populate() throws IOException {
if (description!=null) return; // already populated
root.retrieve().to(url, this);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof GHLicense)) return false;
GHLicense that = (GHLicense) o;
return this.url.equals(that.url);
}
@Override
public int hashCode() {
return url.hashCode();
}
/*package*/ GHLicense wrap(GitHub root) {
this.root = root;
return this;
}
}

View File

@@ -0,0 +1,84 @@
package org.kohsuke.github;
import java.io.IOException;
import java.net.URL;
import java.util.Locale;
/**
* Represents a membership of a user in an organization.
*
* @author Kohsuke Kawaguchi
* @see GHMyself#listOrgMemberships()
*/
public class GHMembership /* extends GHObject --- but it doesn't have id, created_at, etc. */ {
GitHub root;
String url;
String state;
String role;
GHUser user;
GHOrganization organization;
public URL getUrl() {
return GitHub.parseURL(url);
}
public State getState() {
return Enum.valueOf(State.class, state.toUpperCase(Locale.ENGLISH));
}
public Role getRole() {
return Enum.valueOf(Role.class, role.toUpperCase(Locale.ENGLISH));
}
public GHUser getUser() {
return user;
}
public GHOrganization getOrganization() {
return organization;
}
/**
* Accepts a pending invitation to an organization.
*
* @see GHMyself#getMembership(GHOrganization)
*/
public void activate() throws IOException {
root.retrieve().method("PATCH").with("state",State.ACTIVE).to(url,this);
}
/*package*/ GHMembership wrap(GitHub root) {
this.root = root;
if (user!=null) user = root.getUser(user.wrapUp(root));
if (organization!=null) organization.wrapUp(root);
return this;
}
/*package*/ static void wrap(GHMembership[] page, GitHub root) {
for (GHMembership m : page)
m.wrap(root);
}
/**
* Role of a user in an organization.
*/
public enum Role {
/**
* Organization owner.
*/
ADMIN,
/**
* Non-owner organization member.
*/
MEMBER;
}
/**
* Whether a role is currently active or waiting for acceptance (pending)
*/
public enum State {
ACTIVE,
PENDING;
}
}

View File

@@ -27,8 +27,8 @@ public class GHMilestone extends GHObject {
return owner;
}
public GHUser getCreator() {
return creator;
public GHUser getCreator() throws IOException {
return root.intern(creator);
}
public Date getDueOn() {
@@ -72,16 +72,42 @@ public class GHMilestone extends GHObject {
}
/**
* Closes this issue.
* Closes this milestone.
*/
public void close() throws IOException {
edit("state", "closed");
}
/**
* Reopens this milestone.
*/
public void reopen() throws IOException {
edit("state", "open");
}
/**
* Deletes this milestone.
*/
public void delete() throws IOException {
root.retrieve().method("DELETE").to(getApiRoute());
}
private void edit(String key, Object value) throws IOException {
new Requester(root)._with(key, value).method("PATCH").to(getApiRoute());
}
public void setTitle(String title) throws IOException {
edit("title", title);
}
public void setDescription(String description) throws IOException {
edit("description", description);
}
public void setDueOn(Date dueOn) throws IOException {
edit("due_on", GitHub.printDate(dueOn));
}
protected String getApiRoute() {
return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/milestones/"+number;
}

View File

@@ -6,7 +6,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
@@ -157,18 +156,13 @@ public class GHMyself extends GHUser {
* @param repoType type of repository returned in the listing
*/
public PagedIterable<GHRepository> listRepositories(final int pageSize, final RepositoryListFilter repoType) {
return new PagedIterable<GHRepository>() {
public PagedIterator<GHRepository> iterator() {
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/user/repos?per_page=" + pageSize +
"&type=" + repoType.name().toLowerCase(Locale.ENGLISH), GHRepository[].class)) {
@Override
protected void wrapUp(GHRepository[] page) {
for (GHRepository c : page)
c.wrap(root);
}
};
}
};
return root.retrieve()
.with("type",repoType)
.asPagedIterable(
"/user/repos",
GHRepository[].class,
item -> item.wrap(root)
).withPageSize(pageSize);
}
/**
@@ -179,6 +173,35 @@ public class GHMyself extends GHUser {
return listRepositories();
}
/**
* List your organization memberships
*/
public PagedIterable<GHMembership> listOrgMemberships() {
return listOrgMemberships(null);
}
/**
* List your organization memberships
*
* @param state
* Filter by a specific state
*/
public PagedIterable<GHMembership> listOrgMemberships(final GHMembership.State state) {
return root.retrieve()
.with("state",state)
.asPagedIterable(
"/user/memberships/orgs",
GHMembership[].class,
item -> item.wrap(root) );
}
/**
* Gets your membership in a specific organization.
*/
public GHMembership getMembership(GHOrganization o) throws IOException {
return root.retrieve().to("/user/memberships/orgs/"+o.getLogin(),GHMembership.class).wrap(root);
}
// public void addEmails(Collection<String> emails) throws IOException {
//// new Requester(root,ApiVersion.V3).withCredential().to("/user/emails");
// root.retrieveWithAuth3()

View File

@@ -2,10 +2,16 @@ package org.kohsuke.github;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.annotation.CheckForNull;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* Most (all?) domain objects in GitHub seems to have these 4 properties.
@@ -13,14 +19,34 @@ import java.util.Date;
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
public abstract class GHObject {
/**
* Capture response HTTP headers on the state object.
*/
protected Map<String, List<String>> responseHeaderFields;
protected String url;
protected int id;
protected long id;
protected String created_at;
protected String updated_at;
/*package*/ GHObject() {
}
/**
* Returns the HTTP response headers given along with the state of this object.
*
* <p>
* Some of the HTTP headers have nothing to do with the object, for example "Cache-Control"
* and others are different depending on how this object was retrieved.
*
* This method was added as a kind of hack to allow the caller to retrieve OAuth scopes and such.
* Use with caution. The method might be removed in the future.
*/
@CheckForNull @Deprecated
public Map<String, List<String>> getResponseHeaderFields() {
return responseHeaderFields;
}
/**
* When was this resource created?
*/
@@ -46,7 +72,7 @@ public abstract class GHObject {
* URL of this object for humans, which renders some HTML.
*/
@WithBridgeMethods(value=String.class, adapterMethod="urlToString")
public abstract URL getHtmlUrl();
public abstract URL getHtmlUrl() throws IOException;
/**
* When was this resource last updated?
@@ -58,18 +84,57 @@ public abstract class GHObject {
/**
* Unique ID number of this resource.
*/
@WithBridgeMethods(value=String.class, adapterMethod="intToString")
public int getId() {
@WithBridgeMethods(value={String.class,int.class}, adapterMethod="longToStringOrInt")
public long getId() {
return id;
}
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getId")
private Object intToString(int id, Class type) {
return String.valueOf(id);
private Object longToStringOrInt(long id, Class type) {
if (type==String.class)
return String.valueOf(id);
if (type==int.class)
return (int)id;
throw new AssertionError("Unexpected type: "+type);
}
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getHtmlUrl")
private Object urlToString(URL url, Class type) {
return url==null ? null : url.toString();
}
/**
* String representation to assist debugging and inspection. The output format of this string
* is not a committed part of the API and is subject to change.
*/
@Override
public String toString() {
return new ReflectionToStringBuilder(this, TOSTRING_STYLE, null, null, false, false) {
@Override
protected boolean accept(Field field) {
return super.accept(field) && !field.isAnnotationPresent(SkipFromToString.class);
}
}.toString();
}
private static final ToStringStyle TOSTRING_STYLE = new ToStringStyle() {
{
this.setUseShortClassName(true);
}
@Override
public void append(StringBuffer buffer, String fieldName, Object value, Boolean fullDetail) {
// skip unimportant properties. '_' is a heuristics as important properties tend to have short names
if (fieldName.contains("_"))
return;
// avoid recursing other GHObject
if (value instanceof GHObject)
return;
// likewise no point in showing root
if (value instanceof GitHub)
return;
super.append(buffer,fieldName,value,fullDetail);
}
};
}

View File

@@ -7,9 +7,9 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import static org.kohsuke.github.Previews.INERTIA;
/**
* @author Kohsuke Kawaguchi
@@ -24,6 +24,8 @@ public class GHOrganization extends GHPerson {
*
* @return
* Newly created repository.
* @deprecated
* Use {@link #createRepository(String)} that uses a builder pattern to let you control every aspect.
*/
public GHRepository createRepository(String name, String description, String homepage, String team, boolean isPublic) throws IOException {
GHTeam t = getTeams().get(team);
@@ -32,13 +34,25 @@ public class GHOrganization extends GHPerson {
return createRepository(name, description, homepage, t, isPublic);
}
/**
* @deprecated
* Use {@link #createRepository(String)} that uses a builder pattern to let you control every aspect.
*/
public GHRepository createRepository(String name, String description, String homepage, GHTeam team, boolean isPublic) throws IOException {
if (team==null)
throw new IllegalArgumentException("Invalid team");
// such API doesn't exist, so fall back to HTML scraping
return new Requester(root)
.with("name", name).with("description", description).with("homepage", homepage)
.with("public", isPublic).with("team_id",team.getId()).to("/orgs/"+login+"/repos", GHRepository.class).wrap(root);
return createRepository(name).description(description).homepage(homepage).private_(!isPublic).team(team).create();
}
/**
* Starts a builder that creates a new repository.
*
* <p>
* You use the returned builder to set various properties, then call {@link GHCreateRepositoryBuilder#create()}
* to finally createa repository.
*/
public GHCreateRepositoryBuilder createRepository(String name) {
return new GHCreateRepositoryBuilder(root,"/orgs/"+login+"/repos",name);
}
/**
@@ -56,17 +70,11 @@ public class GHOrganization extends GHPerson {
* List up all the teams.
*/
public PagedIterable<GHTeam> listTeams() throws IOException {
return new PagedIterable<GHTeam>() {
public PagedIterator<GHTeam> iterator() {
return new PagedIterator<GHTeam>(root.retrieve().asIterator(String.format("/orgs/%s/teams", login), GHTeam[].class)) {
@Override
protected void wrapUp(GHTeam[] page) {
for (GHTeam c : page)
c.wrapUp(GHOrganization.this);
}
};
}
};
return root.retrieve()
.asPagedIterable(
String.format("/orgs/%s/teams", login),
GHTeam[].class,
item -> item.wrapUp(GHOrganization.this) );
}
/**
@@ -80,6 +88,33 @@ public class GHOrganization extends GHPerson {
return null;
}
/**
* Finds a team that has the given slug in its {@link GHTeam#getSlug()}
*/
public GHTeam getTeamBySlug(String slug) throws IOException {
for (GHTeam t : listTeams()) {
if(t.getSlug().equals(slug))
return t;
}
return null;
}
/** Member's role in an organization */
public enum Role {
ADMIN, /** The user is an owner of the organization. */
MEMBER /** The user is a non-owner member of the organization. */
}
/**
* Adds (invites) a user to the organization.
* @see <a href="https://developer.github.com/v3/orgs/members/#add-or-update-organization-membership">documentation</a>
*/
public void add(GHUser user, Role role) throws IOException {
root.retrieve().method("PUT")
.with("role", role.name().toLowerCase())
.to("/orgs/" + login + "/memberships/" + user.getLogin());
}
/**
* Checks if this organization has the specified user as a member.
*/
@@ -149,17 +184,12 @@ public class GHOrganization extends GHPerson {
}
private PagedIterable<GHUser> listMembers(final String suffix, final String filter) throws IOException {
return new PagedIterable<GHUser>() {
public PagedIterator<GHUser> iterator() {
String filterParams = (filter == null) ? "" : ("?filter=" + filter);
return new PagedIterator<GHUser>(root.retrieve().asIterator(String.format("/orgs/%s/%s%s", login, suffix, filterParams), GHUser[].class)) {
@Override
protected void wrapUp(GHUser[] users) {
GHUser.wrap(users, root);
}
};
}
};
String filterParams = (filter == null) ? "" : ("?filter=" + filter);
return root.retrieve()
.asPagedIterable(
String.format("/orgs/%s/%s%s", login, suffix, filterParams),
GHUser[].class,
item -> item.wrapUp(root) );
}
/**
@@ -169,23 +199,54 @@ public class GHOrganization extends GHPerson {
root.retrieve().method("DELETE").to("/orgs/" + login + "/public_members/" + u.getLogin(), null);
}
/**
* Returns the projects for this organization.
* @param status The status filter (all, open or closed).
*/
public PagedIterable<GHProject> listProjects(final GHProject.ProjectStateFilter status) throws IOException {
return root.retrieve().withPreview(INERTIA)
.with("state", status)
.asPagedIterable(
String.format("/orgs/%s/projects", login),
GHProject[].class,
item -> item.wrap(root) );
}
/**
* Returns all open projects for the organization.
*/
public PagedIterable<GHProject> listProjects() throws IOException {
return listProjects(GHProject.ProjectStateFilter.OPEN);
}
/**
* Creates a project for the organization.
*/
public GHProject createProject(String name, String body) throws IOException {
return root.retrieve().method("POST")
.withPreview(INERTIA)
.with("name", name)
.with("body", body)
.to(String.format("/orgs/%s/projects", login), GHProject.class).wrap(root);
}
public enum Permission { ADMIN, PUSH, PULL }
/**
* Creates a new team and assigns the repositories.
*/
public GHTeam createTeam(String name, Permission p, Collection<GHRepository> repositories) throws IOException {
Requester post = new Requester(root).with("name", name).with("permission", p.name().toLowerCase(Locale.ENGLISH));
Requester post = new Requester(root).with("name", name).with("permission", p);
List<String> repo_names = new ArrayList<String>();
for (GHRepository r : repositories) {
repo_names.add(r.getName());
repo_names.add(login + "/" + r.getName());
}
post.with("repo_names",repo_names);
return post.method("POST").to("/orgs/" + login + "/teams", GHTeam.class).wrapUp(this);
}
public GHTeam createTeam(String name, Permission p, GHRepository... repositories) throws IOException {
return createTeam(name,p, Arrays.asList(repositories));
return createTeam(name, p, Arrays.asList(repositories));
}
/**
@@ -196,7 +257,7 @@ public class GHOrganization extends GHPerson {
*/
public List<GHRepository> getRepositoriesWithOpenPullRequests() throws IOException {
List<GHRepository> r = new ArrayList<GHRepository>();
for (GHRepository repository : listRepositories()) {
for (GHRepository repository : listRepositories(100)) {
repository.wrap(root);
List<GHPullRequest> pullRequests = repository.getPullRequests(GHIssueState.OPEN);
if (pullRequests.size() > 0) {
@@ -221,17 +282,11 @@ public class GHOrganization extends GHPerson {
* Lists events performed by a user (this includes private events if the caller is authenticated.
*/
public PagedIterable<GHEventInfo> listEvents() throws IOException {
return new PagedIterable<GHEventInfo>() {
public PagedIterator<GHEventInfo> iterator() {
return new PagedIterator<GHEventInfo>(root.retrieve().asIterator(String.format("/orgs/%s/events", login), GHEventInfo[].class)) {
@Override
protected void wrapUp(GHEventInfo[] page) {
for (GHEventInfo c : page)
c.wrapUp(root);
}
};
}
};
return root.retrieve()
.asPagedIterable(
String.format("/orgs/%s/events", login),
GHEventInfo[].class,
item -> item.wrapUp(root) );
}
/**
@@ -243,17 +298,12 @@ public class GHOrganization extends GHPerson {
*/
@Override
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
return new PagedIterable<GHRepository>() {
public PagedIterator<GHRepository> iterator() {
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/orgs/" + login + "/repos?per_page=" + pageSize, GHRepository[].class)) {
@Override
protected void wrapUp(GHRepository[] page) {
for (GHRepository c : page)
c.wrap(root);
}
};
}
};
return root.retrieve()
.asPagedIterable(
"/orgs/" + login + "/repos",
GHRepository[].class,
item -> item.wrap(root)
).withPageSize(pageSize);
}
/**

View File

@@ -0,0 +1,59 @@
/*
* The MIT License
*
* Copyright 2016 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.kohsuke.github;
import java.util.Locale;
/**
* Permission for a user in a repository.
* @see <a href="https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level">API</a>
*/
/*package*/ class GHPermission {
private String permission;
private GHUser user;
/**
* @return one of {@code admin}, {@code write}, {@code read}, or {@code none}
*/
public String getPermission() {
return permission;
}
public GHPermissionType getPermissionType() {
return Enum.valueOf(GHPermissionType.class, permission.toUpperCase(Locale.ENGLISH));
}
public GHUser getUser() {
return user;
}
void wrapUp(GitHub root) {
if (user != null) {
user.root = root;
}
}
}

View File

@@ -0,0 +1,11 @@
package org.kohsuke.github;
/**
* @author Kohsuke Kawaguchi
*/
public enum GHPermissionType {
ADMIN,
WRITE,
READ,
NONE
}

View File

@@ -38,8 +38,12 @@ public abstract class GHPerson extends GHObject {
* Depending on the original API call where this object is created, it may not contain everything.
*/
protected synchronized void populate() throws IOException {
if (created_at!=null) return; // already populated
if (created_at!=null) {
return; // already populated
}
if (root == null || root.isOffline()) {
return; // cannot populate, will have to live with what we have
}
root.retrieve().to(url, this);
}
@@ -52,7 +56,7 @@ public abstract class GHPerson extends GHObject {
*/
public synchronized Map<String,GHRepository> getRepositories() throws IOException {
Map<String,GHRepository> repositories = new TreeMap<String, GHRepository>();
for (GHRepository r : listRepositories()) {
for (GHRepository r : listRepositories(100)) {
repositories.put(r.getName(),r);
}
return Collections.unmodifiableMap(repositories);
@@ -75,36 +79,32 @@ public abstract class GHPerson extends GHObject {
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
*/
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
return new PagedIterable<GHRepository>() {
public PagedIterator<GHRepository> iterator() {
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/users/" + login + "/repos?per_page=" + pageSize, GHRepository[].class)) {
@Override
protected void wrapUp(GHRepository[] page) {
for (GHRepository c : page)
c.wrap(root);
}
};
}
};
return root.retrieve()
.asPagedIterable(
"/users/" + login + "/repos",
GHRepository[].class,
item -> item.wrap(root)
).withPageSize(pageSize);
}
/**
* Loads repository list in a pagenated fashion.
*
* Loads repository list in a paginated fashion.
*
* <p>
* For a person with a lot of repositories, GitHub returns the list of repositories in a pagenated fashion.
* For a person with a lot of repositories, GitHub returns the list of repositories in a paginated fashion.
* Unlike {@link #getRepositories()}, this method allows the caller to start processing data as it arrives.
*
*
* Every {@link Iterator#next()} call results in I/O. Exceptions that occur during the processing is wrapped
* into {@link Error}.
*
* @deprecated
* Use {@link #listRepositories()}
*/
@Deprecated
public synchronized Iterable<List<GHRepository>> iterateRepositories(final int pageSize) {
return new Iterable<List<GHRepository>>() {
public Iterator<List<GHRepository>> iterator() {
final Iterator<GHRepository[]> pager = root.retrieve().asIterator("/users/" + login + "/repos?per_page="+pageSize,GHRepository[].class);
final Iterator<GHRepository[]> pager = root.retrieve().asIterator("/users/" + login + "/repos",GHRepository[].class, pageSize);
return new Iterator<List<GHRepository>>() {
public boolean hasNext() {
@@ -204,7 +204,7 @@ public abstract class GHPerson extends GHObject {
public Date getUpdatedAt() throws IOException {
populate();
return super.getCreatedAt();
return super.getUpdatedAt();
}
/**

View File

@@ -0,0 +1,183 @@
/*
* The MIT License
*
* Copyright 2018 Martin van Zijl.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.kohsuke.github;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.Locale;
import static org.kohsuke.github.Previews.INERTIA;
/**
* A GitHub project.
* @see <a href="https://developer.github.com/v3/projects/">Projects</a>
* @author Martin van Zijl
*/
public class GHProject extends GHObject {
protected GitHub root;
protected GHObject owner;
private String owner_url;
private String html_url;
private String node_id;
private String name;
private String body;
private int number;
private String state;
private GHUser creator;
@Override
public URL getHtmlUrl() throws IOException {
return GitHub.parseURL(html_url);
}
public GitHub getRoot() {
return root;
}
public GHObject getOwner() throws IOException {
if(owner == null) {
try {
if(owner_url.contains("/orgs/")) {
owner = root.retrieve().to(getOwnerUrl().getPath(), GHOrganization.class).wrapUp(root);
} else if(owner_url.contains("/users/")) {
owner = root.retrieve().to(getOwnerUrl().getPath(), GHUser.class).wrapUp(root);
} else if(owner_url.contains("/repos/")) {
owner = root.retrieve().to(getOwnerUrl().getPath(), GHRepository.class).wrap(root);
}
} catch (FileNotFoundException e) {
return null;
}
}
return owner;
}
public URL getOwnerUrl() {
return GitHub.parseURL(owner_url);
}
public String getNode_id() {
return node_id;
}
public String getName() {
return name;
}
public String getBody() {
return body;
}
public int getNumber() {
return number;
}
public ProjectState getState() {
return Enum.valueOf(ProjectState.class, state.toUpperCase(Locale.ENGLISH));
}
public GHUser getCreator() {
return creator;
}
public GHProject wrap(GHRepository repo) {
this.owner = repo;
this.root = repo.root;
return this;
}
public GHProject wrap(GitHub root) {
this.root = root;
return this;
}
private void edit(String key, Object value) throws IOException {
new Requester(root).withPreview(INERTIA)._with(key, value).method("PATCH").to(getApiRoute());
}
protected String getApiRoute() {
return "/projects/" + id;
}
public void setName(String name) throws IOException {
edit("name", name);
}
public void setBody(String body) throws IOException {
edit("body", body);
}
public enum ProjectState {
OPEN,
CLOSED
}
public void setState(ProjectState state) throws IOException {
edit("state", state.toString().toLowerCase());
}
public static enum ProjectStateFilter {
ALL,
OPEN,
CLOSED
}
/**
* Set the permission level that all members of the project's organization will have on this project.
* Only applicable for organization-owned projects.
*/
public void setOrganizationPermission(GHPermissionType permission) throws IOException {
edit("organization_permission", permission.toString().toLowerCase());
}
/**
* Sets visibility of the project within the organization.
* Only applicable for organization-owned projects.
*/
public void setPublic(boolean isPublic) throws IOException {
edit("public", isPublic);
}
public void delete() throws IOException {
new Requester(root).withPreview(INERTIA).method("DELETE").to(getApiRoute());
}
public PagedIterable<GHProjectColumn> listColumns() throws IOException {
final GHProject project = this;
return root.retrieve()
.withPreview(INERTIA)
.asPagedIterable(
String.format("/projects/%d/columns", id),
GHProjectColumn[].class,
item -> item.wrap(project) );
}
public GHProjectColumn createColumn(String name) throws IOException {
return root.retrieve().method("POST")
.withPreview(INERTIA)
.with("name", name)
.to(String.format("/projects/%d/columns", id), GHProjectColumn.class).wrap(this);
}
}

View File

@@ -0,0 +1,123 @@
package org.kohsuke.github;
import org.apache.commons.lang3.StringUtils;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import static org.kohsuke.github.Previews.INERTIA;
/**
* @author Gunnar Skjold
*/
public class GHProjectCard extends GHObject {
private GitHub root;
private GHProject project;
private GHProjectColumn column;
private String note;
private GHUser creator;
private String content_url, project_url, column_url;
private boolean archived;
public URL getHtmlUrl() throws IOException {
return null;
}
public GHProjectCard wrap(GitHub root) {
this.root = root;
return this;
}
public GHProjectCard wrap(GHProjectColumn column) {
this.column = column;
this.project = column.project;
this.root = column.root;
return this;
}
public GitHub getRoot() {
return root;
}
public GHProject getProject() throws IOException {
if(project == null) {
try {
project = root.retrieve().to(getProjectUrl().getPath(), GHProject.class).wrap(root);
} catch (FileNotFoundException e) {
return null;
}
}
return project;
}
public GHProjectColumn getColumn() throws IOException {
if(column == null) {
try {
column = root.retrieve().to(getColumnUrl().getPath(), GHProjectColumn.class).wrap(root);
} catch (FileNotFoundException e) {
return null;
}
}
return column;
}
public GHIssue getContent() throws IOException {
if(StringUtils.isEmpty(content_url))
return null;
try {
if(content_url.contains("/pulls")) {
return root.retrieve().to(getContentUrl().getPath(), GHPullRequest.class).wrap(root);
} else {
return root.retrieve().to(getContentUrl().getPath(), GHIssue.class).wrap(root);
}
} catch (FileNotFoundException e) {
return null;
}
}
public String getNote() {
return note;
}
public GHUser getCreator() {
return creator;
}
public URL getContentUrl() {
return GitHub.parseURL(content_url);
}
public URL getProjectUrl() {
return GitHub.parseURL(project_url);
}
public URL getColumnUrl() {
return GitHub.parseURL(column_url);
}
public boolean isArchived() {
return archived;
}
public void setNote(String note) throws IOException {
edit("note", note);
}
public void setArchived(boolean archived) throws IOException {
edit("archived", archived);
}
private void edit(String key, Object value) throws IOException {
new Requester(root).withPreview(INERTIA)._with(key, value).method("PATCH").to(getApiRoute());
}
protected String getApiRoute() {
return String.format("/projects/columns/cards/%d", id);
}
public void delete() throws IOException {
new Requester(root).withPreview(INERTIA).method("DELETE").to(getApiRoute());
}
}

View File

@@ -0,0 +1,98 @@
package org.kohsuke.github;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import static org.kohsuke.github.Previews.INERTIA;
/**
* @author Gunnar Skjold
*/
public class GHProjectColumn extends GHObject {
protected GitHub root;
protected GHProject project;
private String name;
private String project_url;
@Override
public URL getHtmlUrl() throws IOException {
return null;
}
public GHProjectColumn wrap(GitHub root) {
this.root = root;
return this;
}
public GHProjectColumn wrap(GHProject project) {
this.project = project;
this.root = project.root;
return this;
}
public GitHub getRoot() {
return root;
}
public GHProject getProject() throws IOException {
if(project == null) {
try {
project = root.retrieve().to(getProjectUrl().getPath(), GHProject.class).wrap(root);
} catch (FileNotFoundException e) {
return null;
}
}
return project;
}
public String getName() {
return name;
}
public URL getProjectUrl() {
return GitHub.parseURL(project_url);
}
public void setName(String name) throws IOException {
edit("name", name);
}
private void edit(String key, Object value) throws IOException {
new Requester(root).withPreview(INERTIA)._with(key, value).method("PATCH").to(getApiRoute());
}
protected String getApiRoute() {
return String.format("/projects/columns/%d", id);
}
public void delete() throws IOException {
new Requester(root).withPreview(INERTIA).method("DELETE").to(getApiRoute());
}
public PagedIterable<GHProjectCard> listCards() throws IOException {
final GHProjectColumn column = this;
return root.retrieve()
.withPreview(INERTIA)
.asPagedIterable(
String.format("/projects/columns/%d/cards", id),
GHProjectCard[].class,
item -> item.wrap(column) );
}
public GHProjectCard createCard(String note) throws IOException {
return root.retrieve().method("POST")
.withPreview(INERTIA)
.with("note", note)
.to(String.format("/projects/columns/%d/cards", id), GHProjectCard.class).wrap(this);
}
public GHProjectCard createCard(GHIssue issue) throws IOException {
return root.retrieve().method("POST")
.withPreview(INERTIA)
.with("content_type", issue instanceof GHPullRequest ? "PullRequest" : "Issue")
.with("content_id", issue.getId())
.to(String.format("/projects/columns/%d/cards", id), GHProjectCard.class).wrap(this);
}
}

View File

@@ -23,19 +23,29 @@
*/
package org.kohsuke.github;
import javax.annotation.CheckForNull;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import static org.kohsuke.github.Previews.SHADOW_CAT;
/**
* A pull request.
*
*
* @author Kohsuke Kawaguchi
* @see GHRepository#getPullRequest(int)
*/
@SuppressWarnings({"UnusedDeclaration"})
public class GHPullRequest extends GHIssue {
public class GHPullRequest extends GHIssue implements Refreshable {
private static final String COMMENTS_ACTION = "/comments";
private static final String REQUEST_REVIEWERS = "/requested_reviewers";
private String patch_url, diff_url, issue_url;
private GHCommitPointer base;
@@ -44,14 +54,20 @@ public class GHPullRequest extends GHIssue {
// details that are only available when obtained from ID
private GHUser merged_by;
private int review_comments, additions;
private boolean merged;
private int review_comments, additions, commits;
private boolean merged, maintainer_can_modify;
// making these package private to all for testing
boolean draft;
private Boolean mergeable;
private int deletions;
private String mergeable_state;
private int changed_files;
private String merge_commit_sha;
// pull request reviewers
private GHUser[] requested_reviewers;
private GHTeam[] requested_teams;
/**
* GitHub doesn't return some properties of {@link GHIssue} when requesting the GET on the 'pulls' API
* route as opposed to 'issues' API route. This flag remembers whether we made the GET call on the 'issues' route
@@ -70,6 +86,8 @@ public class GHPullRequest extends GHIssue {
if (base != null) base.wrapUp(root);
if (head != null) head.wrapUp(root);
if (merged_by != null) merged_by.wrapUp(root);
if (requested_reviewers != null) GHUser.wrap(requested_reviewers, root);
if (requested_teams != null) GHTeam.wrapUp(requested_teams, this);
return this;
}
@@ -85,7 +103,7 @@ public class GHPullRequest extends GHIssue {
public URL getPatchUrl() {
return GitHub.parseURL(patch_url);
}
/**
* The URL of the patch file.
* like https://github.com/jenkinsci/jenkins/pull/100.patch
@@ -108,7 +126,7 @@ public class GHPullRequest extends GHIssue {
public GHCommitPointer getHead() {
return head;
}
@Deprecated
public Date getIssueUpdatedAt() throws IOException {
return super.getUpdatedAt();
@@ -161,16 +179,48 @@ public class GHPullRequest extends GHIssue {
return additions;
}
public int getCommits() throws IOException {
populate();
return commits;
}
public boolean isMerged() throws IOException {
populate();
return merged;
}
public Boolean getMergeable() throws IOException {
public boolean canMaintainerModify() throws IOException {
populate();
return maintainer_can_modify;
}
public boolean isDraft() throws IOException {
populate();
return draft;
}
/**
* Is this PR mergeable?
*
* @return
* null if the state has not been determined yet, for example when a PR is newly created.
* If this method is called on an instance whose mergeable state is not yet known,
* API call is made to retrieve the latest state.
*/
public Boolean getMergeable() throws IOException {
refresh(mergeable);
return mergeable;
}
/**
* for test purposes only
*/
@Deprecated
Boolean getMergeableNoRefresh() throws IOException {
return mergeable;
}
public int getDeletions() throws IOException {
populate();
return deletions;
@@ -194,67 +244,106 @@ public class GHPullRequest extends GHIssue {
return merge_commit_sha;
}
public List<GHUser> getRequestedReviewers() throws IOException {
refresh(requested_reviewers);
return Collections.unmodifiableList(Arrays.asList(requested_reviewers));
}
public List<GHTeam> getRequestedTeams() throws IOException {
refresh(requested_teams);
return Collections.unmodifiableList(Arrays.asList(requested_teams));
}
/**
* Fully populate the data by retrieving missing data.
*
* Depending on the original API call where this object is created, it may not contain everything.
*/
private void populate() throws IOException {
if (merged_by!=null) return; // already populated
root.retrieve().to(url, this).wrapUp(owner);
if (mergeable_state!=null) return; // already populated
refresh();
}
/**
* Retrieves all the commits associated to this pull request.
* Repopulates this object.
*/
public void refresh() throws IOException {
if (root.isOffline()) {
return; // cannot populate, will have to live with what we have
}
root.retrieve()
.withPreview(SHADOW_CAT)
.to(url, this).wrapUp(owner);
}
/**
* Retrieves all the files associated to this pull request.
*/
public PagedIterable<GHPullRequestFileDetail> listFiles() {
return new PagedIterable<GHPullRequestFileDetail>() {
public PagedIterator<GHPullRequestFileDetail> iterator() {
return new PagedIterator<GHPullRequestFileDetail>(root.retrieve().asIterator(String.format("%s/files", getApiURL()),
GHPullRequestFileDetail[].class)) {
@Override
protected void wrapUp(GHPullRequestFileDetail[] page) {
}
};
}
};
return root.retrieve()
.asPagedIterable(
String.format("%s/files", getApiRoute()),
GHPullRequestFileDetail[].class,
null);
}
/**
* Retrieves all the reviews associated to this pull request.
*/
public PagedIterable<GHPullRequestReview> listReviews() {
return root.retrieve()
.asPagedIterable(
String.format("%s/reviews", getApiRoute()),
GHPullRequestReview[].class,
item -> item.wrapUp(GHPullRequest.this));
}
/**
* Obtains all the review comments associated with this pull request.
*/
public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException {
return new PagedIterable<GHPullRequestReviewComment>() {
public PagedIterator<GHPullRequestReviewComment> iterator() {
return new PagedIterator<GHPullRequestReviewComment>(root.retrieve().asIterator(getApiRoute() + "/comments",
GHPullRequestReviewComment[].class)) {
protected void wrapUp(GHPullRequestReviewComment[] page) {
for (GHPullRequestReviewComment c : page)
c.wrapUp(GHPullRequest.this);
}
};
}
};
return root.retrieve()
.asPagedIterable(
getApiRoute() + COMMENTS_ACTION,
GHPullRequestReviewComment[].class,
item -> item.wrapUp(GHPullRequest.this) );
}
/**
* Retrieves all the commits associated to this pull request.
*/
public PagedIterable<GHPullRequestCommitDetail> listCommits() {
return new PagedIterable<GHPullRequestCommitDetail>() {
public PagedIterator<GHPullRequestCommitDetail> iterator() {
return new PagedIterator<GHPullRequestCommitDetail>(root.retrieve().asIterator(
String.format("%s/commits", getApiURL()),
GHPullRequestCommitDetail[].class)) {
@Override
protected void wrapUp(GHPullRequestCommitDetail[] page) {
for (GHPullRequestCommitDetail c : page)
c.wrapUp(GHPullRequest.this);
}
};
}
};
return root.retrieve()
.asPagedIterable(
String.format("%s/commits", getApiRoute()),
GHPullRequestCommitDetail[].class,
item -> item.wrapUp(GHPullRequest.this) );
}
/**
* @deprecated
* Use {@link #createReview()}
*/
public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequestReviewState event,
GHPullRequestReviewComment... comments) throws IOException {
return createReview(body, event, Arrays.asList(comments));
}
/**
* @deprecated
* Use {@link #createReview()}
*/
public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequestReviewState event,
List<GHPullRequestReviewComment> comments) throws IOException {
GHPullRequestReviewBuilder b = createReview().body(body);
for (GHPullRequestReviewComment c : comments) {
b.comment(c.getBody(), c.getPath(), c.getPosition());
}
return b.create();
}
public GHPullRequestReviewBuilder createReview() {
return new GHPullRequestReviewBuilder(this);
}
public GHPullRequestReviewComment createReviewComment(String body, String sha, String path, int position) throws IOException {
@@ -263,7 +352,23 @@ public class GHPullRequest extends GHIssue {
.with("commit_id", sha)
.with("path", path)
.with("position", position)
.to(getApiRoute() + "/comments", GHPullRequestReviewComment.class).wrapUp(this);
.to(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment.class).wrapUp(this);
}
public void requestReviewers(List<GHUser> reviewers) throws IOException {
new Requester(root).method("POST")
.withLogins("reviewers", reviewers)
.to(getApiRoute() + REQUEST_REVIEWERS);
}
public void requestTeamReviewers(List<GHTeam> teams) throws IOException {
List<String> teamReviewers = new ArrayList<String>(teams.size());
for (GHTeam team : teams) {
teamReviewers.add(team.getSlug());
}
new Requester(root).method("POST")
.with("team_reviewers", teamReviewers)
.to(getApiRoute() + REQUEST_REVIEWERS);
}
/**
@@ -289,12 +394,32 @@ public class GHPullRequest extends GHIssue {
* SHA that pull request head must match to allow merge.
*/
public void merge(String msg, String sha) throws IOException {
new Requester(root).method("PUT").with("commit_message",msg).with("sha",sha).to(getApiRoute()+"/merge");
merge(msg, sha, null);
}
/**
* Merge this pull request, using the specified merge method.
*
* The equivalent of the big green "Merge pull request" button.
*
* @param msg
* Commit message. If null, the default one will be used.
* @param method
* SHA that pull request head must match to allow merge.
*/
public void merge(String msg, String sha, MergeMethod method) throws IOException {
new Requester(root).method("PUT")
.with("commit_message", msg)
.with("sha", sha)
.with("merge_method", method)
.to(getApiRoute() + "/merge");
}
public enum MergeMethod{ MERGE, SQUASH, REBASE }
private void fetchIssue() throws IOException {
if (!fetchedIssueDetails) {
new Requester(root).to(getIssuesApiRoute(), this);
new Requester(root).method("GET").to(getIssuesApiRoute(), this);
fetchedIssueDetails = true;
}
}

View File

@@ -27,7 +27,6 @@ import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.net.URL;
import java.util.Arrays;
/**
* Commit detail inside a {@link GHPullRequest}.
@@ -144,6 +143,8 @@ public class GHPullRequestCommitDetail {
}
public CommitPointer[] getParents() {
return Arrays.copyOf(parents, parents.length);
CommitPointer[] newValue = new CommitPointer[parents.length];
System.arraycopy(parents, 0, newValue, 0, parents.length);
return newValue;
}
}

View File

@@ -43,6 +43,7 @@ public class GHPullRequestFileDetail {
String raw_url;
String contents_url;
String patch;
String previous_filename;
public String getSha() {
return sha;
@@ -83,4 +84,9 @@ public class GHPullRequestFileDetail {
public String getPatch() {
return patch;
}
public String getPreviousFilename()
{
return previous_filename;
}
}

View File

@@ -0,0 +1,58 @@
package org.kohsuke.github;
import static org.kohsuke.github.Previews.SHADOW_CAT;
/**
* Lists up pull requests with some filtering and sorting.
*
* @author Kohsuke Kawaguchi
* @see GHRepository#queryPullRequests()
*/
public class GHPullRequestQueryBuilder extends GHQueryBuilder<GHPullRequest> {
private final GHRepository repo;
/*package*/ GHPullRequestQueryBuilder(GHRepository repo) {
super(repo.root);
this.repo = repo;
}
public GHPullRequestQueryBuilder state(GHIssueState state) {
req.with("state",state);
return this;
}
public GHPullRequestQueryBuilder head(String head) {
if (head != null && !head.contains(":")) {
head = repo.getOwnerName() + ":" + head;
}
req.with("head",head);
return this;
}
public GHPullRequestQueryBuilder base(String base) {
req.with("base",base);
return this;
}
public GHPullRequestQueryBuilder sort(Sort sort) {
req.with("sort",sort);
return this;
}
public enum Sort { CREATED, UPDATED, POPULARITY, LONG_RUNNING }
public GHPullRequestQueryBuilder direction(GHDirection d) {
req.with("direction",d);
return this;
}
@Override
public PagedIterable<GHPullRequest> list() {
return req
.withPreview(SHADOW_CAT)
.asPagedIterable(
repo.getApiTailUrl("pulls"),
GHPullRequest[].class,
item -> item.wrapUp(repo) );
}
}

View File

@@ -0,0 +1,157 @@
/*
* The MIT License
*
* Copyright (c) 2017, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.kohsuke.github;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Date;
import javax.annotation.CheckForNull;
import java.io.IOException;
import java.net.URL;
/**
* Review to a pull request.
*
* @see GHPullRequest#listReviews()
* @see GHPullRequestReviewBuilder
*/
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_FIELD"}, justification = "JSON API")
public class GHPullRequestReview extends GHObject {
GHPullRequest owner;
private String body;
private GHUser user;
private String commit_id;
private GHPullRequestReviewState state;
private String submitted_at;
/*package*/ GHPullRequestReview wrapUp(GHPullRequest owner) {
this.owner = owner;
return this;
}
/**
* Gets the pull request to which this review is associated.
*/
public GHPullRequest getParent() {
return owner;
}
/**
* The comment itself.
*/
public String getBody() {
return body;
}
/**
* Gets the user who posted this review.
*/
public GHUser getUser() throws IOException {
return owner.root.getUser(user.getLogin());
}
public String getCommitId() {
return commit_id;
}
@CheckForNull
public GHPullRequestReviewState getState() {
return state;
}
@Override
public URL getHtmlUrl() {
return null;
}
protected String getApiRoute() {
return owner.getApiRoute()+"/reviews/"+id;
}
/**
* When was this resource created?
*/
public Date getSubmittedAt() throws IOException {
return GitHub.parseDate(submitted_at);
}
/**
* Since this method does not exist, we forward this value.
*/
@Override
public Date getCreatedAt() throws IOException {
return getSubmittedAt();
}
/**
* @deprecated
* Former preview method that changed when it got public. Left here for backward compatibility.
* Use {@link #submit(String, GHPullRequestReviewEvent)}
*/
public void submit(String body, GHPullRequestReviewState state) throws IOException {
submit(body,state.toEvent());
}
/**
* Updates the comment.
*/
public void submit(String body, GHPullRequestReviewEvent event) throws IOException {
new Requester(owner.root).method("POST")
.with("body", body)
.with("event", event.action())
.to(getApiRoute()+"/events",this);
this.body = body;
this.state = event.toState();
}
/**
* Deletes this review.
*/
public void delete() throws IOException {
new Requester(owner.root).method("DELETE")
.to(getApiRoute());
}
/**
* Dismisses this review.
*/
public void dismiss(String message) throws IOException {
new Requester(owner.root).method("PUT")
.with("message", message)
.to(getApiRoute()+"/dismissals");
state = GHPullRequestReviewState.DISMISSED;
}
/**
* Obtains all the review comments associated with this pull request review.
*/
public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException {
return owner.root.retrieve()
.asPagedIterable(
getApiRoute() + "/comments",
GHPullRequestReviewComment[].class,
item -> item.wrapUp(owner) );
}
}

View File

@@ -0,0 +1,91 @@
package org.kohsuke.github;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Builds up a creation of new {@link GHPullRequestReview}.
*
* @author Kohsuke Kawaguchi
* @see GHPullRequest#createReview()
*/
public class GHPullRequestReviewBuilder {
private final GHPullRequest pr;
private final Requester builder;
private final List<DraftReviewComment> comments = new ArrayList<DraftReviewComment>();
/*package*/ GHPullRequestReviewBuilder(GHPullRequest pr) {
this.pr = pr;
this.builder = new Requester(pr.root);
}
// public GHPullRequestReview createReview(@Nullable String commitId, String body, GHPullRequestReviewEvent event,
// List<GHPullRequestReviewComment> comments) throws IOException
/**
* The SHA of the commit that needs a review. Not using the latest commit SHA may render your review comment outdated if a subsequent commit modifies the line you specify as the position. Defaults to the most recent commit in the pull request when you do not specify a value.
*/
public GHPullRequestReviewBuilder commitId(String commitId) {
builder.with("commit_id",commitId);
return this;
}
/**
* Required when using REQUEST_CHANGES or COMMENT for the event parameter. The body text of the pull request review.
*/
public GHPullRequestReviewBuilder body(String body) {
builder.with("body",body);
return this;
}
/**
* The review action you want to perform. The review actions include: APPROVE, REQUEST_CHANGES, or COMMENT.
* By leaving this blank, you set the review action state to PENDING,
* which means you will need to {@linkplain GHPullRequestReview#submit(String, GHPullRequestReviewEvent) submit the pull request review} when you are ready.
*/
public GHPullRequestReviewBuilder event(GHPullRequestReviewEvent event) {
builder.with("event",event.action());
return this;
}
/**
* @param body The relative path to the file that necessitates a review comment.
* @param path The position in the diff where you want to add a review comment. Note this value is not the same as the line number in the file. For help finding the position value, read the note below.
* @param position Text of the review comment.
*/
public GHPullRequestReviewBuilder comment(String body, String path, int position) {
comments.add(new DraftReviewComment(body,path,position));
return this;
}
public GHPullRequestReview create() throws IOException {
return builder.method("POST")._with("comments",comments)
.to(pr.getApiRoute() + "/reviews", GHPullRequestReview.class)
.wrapUp(pr);
}
private static class DraftReviewComment {
private String body;
private String path;
private int position;
DraftReviewComment(String body, String path, int position) {
this.body = body;
this.path = path;
this.position = position;
}
public String getBody() {
return body;
}
public String getPath() {
return path;
}
public int getPosition() {
return position;
}
}
}

View File

@@ -25,6 +25,9 @@ package org.kohsuke.github;
import java.io.IOException;
import java.net.URL;
import javax.annotation.CheckForNull;
import static org.kohsuke.github.Previews.*;
/**
* Review comment to the pull request
@@ -33,14 +36,28 @@ import java.net.URL;
* @see GHPullRequest#listReviewComments()
* @see GHPullRequest#createReviewComment(String, String, String, int)
*/
public class GHPullRequestReviewComment extends GHObject {
public class GHPullRequestReviewComment extends GHObject implements Reactable {
GHPullRequest owner;
private String body;
private GHUser user;
private String path;
private int position;
private int originalPosition;
private int position = -1;
private int original_position = -1;
private long in_reply_to_id = -1L;
/**
* @deprecated
* You should be using {@link GHPullRequestReviewBuilder#comment(String, String, int)}
*/
public static GHPullRequestReviewComment draft(String body, String path, int position) {
GHPullRequestReviewComment result = new GHPullRequestReviewComment();
result.body = body;
result.path = path;
result.position = position;
return result;
}
/*package*/ GHPullRequestReviewComment wrapUp(GHPullRequest owner) {
this.owner = owner;
@@ -72,12 +89,18 @@ public class GHPullRequestReviewComment extends GHObject {
return path;
}
@CheckForNull
public int getPosition() {
return position;
}
public int getOriginalPosition() {
return originalPosition;
return original_position;
}
@CheckForNull
public long getInReplyToId() {
return in_reply_to_id;
}
@Override
@@ -103,4 +126,33 @@ public class GHPullRequestReviewComment extends GHObject {
public void delete() throws IOException {
new Requester(owner.root).method("DELETE").to(getApiRoute());
}
/**
* Create a new comment that replies to this comment.
*/
public GHPullRequestReviewComment reply(String body) throws IOException {
return new Requester(owner.root).method("POST")
.with("body", body)
.with("in_reply_to", getId())
.to(getApiRoute() + "/comments", GHPullRequestReviewComment.class)
.wrapUp(owner);
}
@Preview @Deprecated
public GHReaction createReaction(ReactionContent content) throws IOException {
return new Requester(owner.root)
.withPreview(SQUIRREL_GIRL)
.with("content", content.getContent())
.to(getApiRoute()+"/reactions", GHReaction.class).wrap(owner.root);
}
@Preview @Deprecated
public PagedIterable<GHReaction> listReactions() {
return owner.root.retrieve()
.withPreview(SQUIRREL_GIRL)
.asPagedIterable(
getApiRoute() + "/reactions",
GHReaction[].class,
item -> item.wrap(owner.root) );
}
}

View File

@@ -0,0 +1,51 @@
/*
* The MIT License
*
* Copyright (c) 2011, Eric Maupin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.kohsuke.github;
/**
* Action to perform on {@link GHPullRequestReview}.
*/
public enum GHPullRequestReviewEvent {
PENDING,
APPROVE,
REQUEST_CHANGES,
COMMENT;
/*package*/ String action() {
return this==PENDING ? null : name();
}
/**
* When a {@link GHPullRequestReview} is submitted with this event, it should transition to this state.
*/
/*package*/ GHPullRequestReviewState toState() {
switch (this) {
case PENDING: return GHPullRequestReviewState.PENDING;
case APPROVE: return GHPullRequestReviewState.APPROVED;
case REQUEST_CHANGES: return GHPullRequestReviewState.CHANGES_REQUESTED;
case COMMENT: return GHPullRequestReviewState.COMMENTED;
}
throw new IllegalStateException();
}
}

View File

@@ -0,0 +1,39 @@
package org.kohsuke.github;
/**
* Current state of {@link GHPullRequestReview}
*/
public enum GHPullRequestReviewState {
PENDING,
APPROVED,
CHANGES_REQUESTED,
/**
* @deprecated
* This was the thing when this API was in preview, but it changed when it became public.
* Use {@link #CHANGES_REQUESTED}. Left here for compatibility.
*/
REQUEST_CHANGES,
COMMENTED,
DISMISSED;
/**
* @deprecated
* This was an internal method accidentally exposed.
* Left here for compatibility.
*/
public String action() {
GHPullRequestReviewEvent e = toEvent();
return e==null ? null : e.action();
}
/*package*/ GHPullRequestReviewEvent toEvent() {
switch (this) {
case PENDING: return GHPullRequestReviewEvent.PENDING;
case APPROVED: return GHPullRequestReviewEvent.APPROVE;
case CHANGES_REQUESTED: return GHPullRequestReviewEvent.REQUEST_CHANGES;
case REQUEST_CHANGES: return GHPullRequestReviewEvent.REQUEST_CHANGES;
case COMMENTED: return GHPullRequestReviewEvent.COMMENT;
}
return null;
}
}

View File

@@ -0,0 +1,21 @@
package org.kohsuke.github;
/**
* Used to specify filters, sort order, etc for listing items in a collection.
*
* @author Kohsuke Kawaguchi
*/
public abstract class GHQueryBuilder<T> {
protected final GitHub root;
protected final Requester req;
/*package*/ GHQueryBuilder(GitHub root) {
this.root = root;
this.req = root.retrieve();
}
/**
* Start listing items by using the settings built up on this object.
*/
public abstract PagedIterable<T> list();
}

View File

@@ -1,6 +1,7 @@
package org.kohsuke.github;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Date;
/**

View File

@@ -0,0 +1,55 @@
package org.kohsuke.github;
import java.io.IOException;
import java.net.URL;
import static org.kohsuke.github.Previews.*;
/**
* Reaction to issue, comment, PR, and so on.
*
* @author Kohsuke Kawaguchi
* @see Reactable
*/
@Preview @Deprecated
public class GHReaction extends GHObject {
private GitHub root;
private GHUser user;
private ReactionContent content;
/*package*/ GHReaction wrap(GitHub root) {
this.root = root;
user.wrapUp(root);
return this;
}
/**
* The kind of reaction left.
*/
public ReactionContent getContent() {
return content;
}
/**
* User who left the reaction.
*/
public GHUser getUser() {
return user;
}
/**
* Reaction has no HTML URL. Don't call this method.
*/
@Deprecated
public URL getHtmlUrl() {
return null;
}
/**
* Removes this reaction.
*/
public void delete() throws IOException {
new Requester(root).method("DELETE").withPreview(SQUIRREL_GIRL).to("/reactions/"+id);
}
}

View File

@@ -1,6 +1,7 @@
package org.kohsuke.github;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.net.URL;

View File

@@ -3,12 +3,13 @@ package org.kohsuke.github;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import static java.lang.String.format;
import static java.lang.String.*;
/**
* Release in a github repository.
@@ -45,10 +46,12 @@ public class GHRelease extends GHObject {
return draft;
}
/**
* @deprecated
* Use {@link #update()}
*/
public GHRelease setDraft(boolean draft) throws IOException {
edit("draft", draft);
this.draft = draft;
return this;
return update().draft(draft).update();
}
public URL getHtmlUrl() {
@@ -121,16 +124,23 @@ public class GHRelease extends GHObject {
* Java 7 or greater. Options for fixing this for earlier JVMs can be found here
* http://stackoverflow.com/questions/12361090/server-name-indication-sni-on-java but involve more complicated
* handling of the HTTP requests to github's API.
*
* @throws IOException
*/
*/
public GHAsset uploadAsset(File file, String contentType) throws IOException {
FileInputStream s = new FileInputStream(file);
try {
return uploadAsset(file.getName(), s, contentType);
} finally {
s.close();
}
}
public GHAsset uploadAsset(String filename, InputStream stream, String contentType) throws IOException {
Requester builder = new Requester(owner.root);
String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s",
owner.getApiTailUrl(""), getId(), file.getName());
owner.getApiTailUrl(""), getId(), filename);
return builder.contentType(contentType)
.with(new FileInputStream(file))
.with(stream)
.to(url, GHAsset.class).wrap(this);
}
@@ -151,10 +161,10 @@ public class GHRelease extends GHObject {
}
/**
* Edit this release.
* Updates this release via a builder.
*/
private void edit(String key, Object value) throws IOException {
new Requester(root)._with(key, value).method("PATCH").to(owner.getApiTailUrl("releases/"+id));
public GHReleaseUpdater update() {
return new GHReleaseUpdater(this);
}
private String getApiTailUrl(String end) {

View File

@@ -21,9 +21,7 @@ public class GHReleaseBuilder {
* @param body The release notes body.
*/
public GHReleaseBuilder body(String body) {
if (body != null) {
builder.with("body", body);
}
builder.with("body", body);
return this;
}
@@ -33,12 +31,9 @@ public class GHReleaseBuilder {
*
* @param commitish Defaults to the repositorys default branch (usually "master"). Unused if the Git tag
* already exists.
* @return
*/
public GHReleaseBuilder commitish(String commitish) {
if (commitish != null) {
builder.with("target_commitish", commitish);
}
builder.with("target_commitish", commitish);
return this;
}
@@ -57,9 +52,7 @@ public class GHReleaseBuilder {
* @param name the name of the release
*/
public GHReleaseBuilder name(String name) {
if (name != null) {
builder.with("name", name);
}
builder.with("name", name);
return this;
}

View File

@@ -0,0 +1,81 @@
package org.kohsuke.github;
import java.io.IOException;
/**
* Modifies {@link GHRelease}.
*
* @author Kohsuke Kawaguchi
* @see GHRelease#update()
*/
public class GHReleaseUpdater {
private final GHRelease base;
private final Requester builder;
GHReleaseUpdater(GHRelease base) {
this.base = base;
this.builder = new Requester(base.root);
}
public GHReleaseUpdater tag(String tag) {
builder.with("tag_name",tag);
return this;
}
/**
* @param body The release notes body.
*/
public GHReleaseUpdater body(String body) {
builder.with("body", body);
return this;
}
/**
* Specifies the commitish value that determines where the Git tag is created from. Can be any branch or
* commit SHA.
*
* @param commitish Defaults to the repositorys default branch (usually "master"). Unused if the Git tag
* already exists.
*/
public GHReleaseUpdater commitish(String commitish) {
builder.with("target_commitish", commitish);
return this;
}
/**
* Optional.
*
* @param draft {@code true} to create a draft (unpublished) release, {@code false} to create a published one.
* Default is {@code false}.
*/
public GHReleaseUpdater draft(boolean draft) {
builder.with("draft", draft);
return this;
}
/**
* @param name the name of the release
*/
public GHReleaseUpdater name(String name) {
builder.with("name", name);
return this;
}
/**
* Optional
*
* @param prerelease {@code true} to identify the release as a prerelease. {@code false} to identify the release
* as a full release. Default is {@code false}.
*/
public GHReleaseUpdater prerelease(boolean prerelease) {
builder.with("prerelease", prerelease);
return this;
}
public GHRelease update() throws IOException {
return builder
.method("PATCH")
.to(base.owner.getApiTailUrl("releases/"+base.id), GHRelease.class).wrap(base.owner);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,37 @@
package org.kohsuke.github;
import java.util.List;
/**
* Repository clone statistics.
*
* @see GHRepository#getCloneTraffic()
*/
public class GHRepositoryCloneTraffic extends GHRepositoryTraffic {
private List<DailyInfo> clones;
/*package*/ GHRepositoryCloneTraffic() {
}
/*package*/ GHRepositoryCloneTraffic(Integer count, Integer uniques, List<DailyInfo> clones) {
super(count, uniques);
this.clones = clones;
}
public List<DailyInfo> getClones() {
return clones;
}
public List<DailyInfo> getDailyInfo() {
return getClones();
}
public static class DailyInfo extends GHRepositoryTraffic.DailyInfo {
/*package*/ DailyInfo() {
}
/*package*/ DailyInfo(String timestamp, int count, int uniques) {
super(timestamp, count, uniques);
}
}
}

View File

@@ -1,7 +1,5 @@
package org.kohsuke.github;
import java.util.Locale;
/**
* Search repositories.
*
@@ -57,8 +55,17 @@ public class GHRepositorySearchBuilder extends GHSearchBuilder<GHRepository> {
return q("stars:"+v);
}
public GHRepositorySearchBuilder topic(String v) {
return q("topic:"+v);
}
public GHRepositorySearchBuilder order(GHDirection v) {
req.with("order",v);
return this;
}
public GHRepositorySearchBuilder sort(Sort sort) {
req.with("sort",sort.toString().toLowerCase(Locale.ENGLISH));
req.with("sort",sort);
return this;
}

View File

@@ -0,0 +1,22 @@
package org.kohsuke.github;
import java.util.Locale;
/**
* App installation repository selection.
*
* @author Paulo Miguel Almeida
*
* @see GHAppInstallation
*/
public enum GHRepositorySelection {
SELECTED,
ALL;
/**
* Returns GitHub's internal representation of this event.
*/
String symbol() {
return name().toLowerCase(Locale.ENGLISH);
}
}

View File

@@ -0,0 +1,433 @@
package org.kohsuke.github;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
/**
* Statistics for a GitHub repository.
*
* @author Martin van Zijl
*/
public class GHRepositoryStatistics {
private final GHRepository repo;
private final GitHub root;
private static final int MAX_WAIT_ITERATIONS = 3;
private static final int WAIT_SLEEP_INTERVAL = 5000;
public GHRepositoryStatistics(GHRepository repo) {
this.repo = repo;
this.root = repo.root;
}
/**
* Get contributors list with additions, deletions, and commit count. See
* https://developer.github.com/v3/repos/statistics/#get-contributors-list-with-additions-deletions-and-commit-counts
*/
public PagedIterable<ContributorStats> getContributorStats() throws IOException, InterruptedException {
return getContributorStats(true);
}
/**
* @param waitTillReady Whether to sleep the thread if necessary until the
* statistics are ready. This is true by default.
*/
@Preview
@Deprecated
@SuppressWarnings("SleepWhileInLoop")
@SuppressFBWarnings(value = {"RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"}, justification = "JSON API")
public PagedIterable<ContributorStats> getContributorStats(boolean waitTillReady) throws IOException, InterruptedException {
PagedIterable<GHRepositoryStatistics.ContributorStats> stats =
getContributorStatsImpl();
if (stats == null && waitTillReady) {
for (int i = 0; i < MAX_WAIT_ITERATIONS; i += 1) {
// Wait a few seconds and try again.
Thread.sleep(WAIT_SLEEP_INTERVAL);
stats = getContributorStatsImpl();
if (stats != null) {
break;
}
}
}
return stats;
}
/**
* This gets the actual statistics from the server. Returns null if they
* are still being cached.
*/
private PagedIterable<ContributorStats> getContributorStatsImpl() throws IOException {
return root.retrieve()
.asPagedIterable(
getApiTailUrl("contributors"),
ContributorStats[].class,
item -> item.wrapUp(root) );
}
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD"}, justification = "JSON API")
public static class ContributorStats extends GHObject {
/*package almost final*/ private GitHub root;
private GHUser author;
private int total;
private List<Week> weeks;
@Override
public URL getHtmlUrl() throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}
public GitHub getRoot() {
return root;
}
/**
* @return The author described by these statistics.
*/
public GHUser getAuthor() {
return author;
}
/**
* @return The total number of commits authored by the contributor.
*/
public int getTotal() {
return total;
}
/**
* Convenience method to look up week with particular timestamp.
*
* @param timestamp The timestamp to look for.
* @return The week starting with the given timestamp. Throws an
* exception if it is not found.
* @throws NoSuchElementException
*/
public Week getWeek(long timestamp) throws NoSuchElementException {
// maybe store the weeks in a map to make this more efficient?
for (Week week : weeks) {
if (week.getWeekTimestamp() == timestamp) {
return week;
}
}
// this is safer than returning null
throw new NoSuchElementException();
}
/**
* @return The total number of commits authored by the contributor.
*/
public List<Week> getWeeks() {
return weeks;
}
@Override
public String toString() {
return author.getLogin() + " made " + String.valueOf(total)
+ " contributions over " + String.valueOf(weeks.size())
+ " weeks";
}
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD"}, justification = "JSON API")
public static class Week {
private long w;
private int a;
private int d;
private int c;
/**
* @return Start of the week, as a UNIX timestamp.
*/
public long getWeekTimestamp() {
return w;
}
/**
* @return The number of additions for the week.
*/
public int getNumberOfAdditions() {
return a;
}
/**
* @return The number of deletions for the week.
*/
public int getNumberOfDeletions() {
return d;
}
/**
* @return The number of commits for the week.
*/
public int getNumberOfCommits() {
return c;
}
@Override
public String toString() {
return String.format("Week starting %d - Additions: %d, Deletions: %d, Commits: %d", w, a, d, c);
}
}
/*package*/ ContributorStats wrapUp(GitHub root) {
this.root = root;
return this;
}
}
/**
* Get the last year of commit activity data. See
* https://developer.github.com/v3/repos/statistics/#get-the-last-year-of-commit-activity-data
*/
public PagedIterable<CommitActivity> getCommitActivity() throws IOException {
return root.retrieve()
.asPagedIterable(
getApiTailUrl("commit_activity"),
CommitActivity[].class,
item -> item.wrapUp(root) );
}
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
public static class CommitActivity extends GHObject {
/*package almost final*/ private GitHub root;
private List<Integer> days;
private int total;
private long week;
/**
* @return The number of commits for each day of the week. 0 = Sunday, 1
* = Monday, etc.
*/
public List<Integer> getDays() {
return days;
}
/**
* @return The total number of commits for the week.
*/
public int getTotal() {
return total;
}
/**
* @return The start of the week as a UNIX timestamp.
*/
public long getWeek() {
return week;
}
/*package*/ CommitActivity wrapUp(GitHub root) {
this.root = root;
return this;
}
public GitHub getRoot() {
return root;
}
@Override
public URL getHtmlUrl() throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}
}
/**
* Get the number of additions and deletions per week.
* See https://developer.github.com/v3/repos/statistics/#get-the-number-of-additions-and-deletions-per-week
*/
public List<CodeFrequency> getCodeFrequency() throws IOException {
// Map to ArrayLists first, since there are no field names in the
// returned JSON.
try {
InputStream stream = root.retrieve().asStream(getApiTailUrl("code_frequency"));
ObjectMapper mapper = new ObjectMapper();
TypeReference<ArrayList<ArrayList<Integer> > > typeRef =
new TypeReference<ArrayList< ArrayList<Integer> > >() {};
ArrayList<ArrayList <Integer> > list = mapper.readValue(stream, typeRef);
// Convert to proper objects.
ArrayList<CodeFrequency> returnList = new ArrayList<CodeFrequency>();
for(ArrayList<Integer> item: list)
{
CodeFrequency cf = new CodeFrequency(item);
returnList.add(cf);
}
return returnList;
} catch (MismatchedInputException e) {
// This sometimes happens when retrieving code frequency statistics
// for a repository for the first time. It is probably still being
// generated, so return null.
return null;
}
}
public static class CodeFrequency {
private int week;
private int additions;
private int deletions;
private CodeFrequency(ArrayList<Integer> item) {
week = item.get(0);
additions = item.get(1);
deletions = item.get(2);
}
/**
* @return The start of the week as a UNIX timestamp.
*/
public int getWeekTimestamp() {
return week;
}
/**
* @return The number of additions for the week.
*/
public long getAdditions() {
return additions;
}
/**
* @return The number of deletions for the week.
* NOTE: This will be a NEGATIVE number.
*/
public long getDeletions() {
// TODO: Perhaps return Math.abs(deletions),
// since most developers may not expect a negative number.
return deletions;
}
@Override
public String toString() {
return "Week starting " + getWeekTimestamp() + " has " + getAdditions() +
" additions and " + Math.abs(getDeletions()) + " deletions";
}
}
/**
* Get the weekly commit count for the repository owner and everyone else.
* See https://developer.github.com/v3/repos/statistics/#get-the-weekly-commit-count-for-the-repository-owner-and-everyone-else
*/
public Participation getParticipation() throws IOException {
return root.retrieve().to(getApiTailUrl("participation"), Participation.class);
}
public static class Participation extends GHObject {
/*package almost final*/ private GitHub root;
private List<Integer> all;
private List<Integer> owner;
@Override
public URL getHtmlUrl() throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}
public GitHub getRoot() {
return root;
}
/**
* @return The list of commit counts for everyone combined, for the
* last 52 weeks.
*/
public List<Integer> getAllCommits() {
return all;
}
/**
* @return The list of commit counts for the owner, for the
* last 52 weeks.
*/
public List<Integer> getOwnerCommits() {
return owner;
}
/*package*/ Participation wrapUp(GitHub root) {
this.root = root;
return this;
}
}
/**
* Get the number of commits per hour in each day.
* See https://developer.github.com/v3/repos/statistics/#get-the-number-of-commits-per-hour-in-each-day
*/
public List<PunchCardItem> getPunchCard() throws IOException {
// Map to ArrayLists first, since there are no field names in the
// returned JSON.
InputStream stream = root.retrieve().asStream(getApiTailUrl("punch_card"));
ObjectMapper mapper = new ObjectMapper();
TypeReference<ArrayList<ArrayList<Integer> > > typeRef =
new TypeReference<ArrayList< ArrayList<Integer> > >() {};
ArrayList<ArrayList <Integer> > list = mapper.readValue(stream, typeRef);
// Convert to proper objects.
ArrayList<PunchCardItem> returnList = new ArrayList<PunchCardItem>();
for(ArrayList<Integer> item: list) {
PunchCardItem pci = new PunchCardItem(item);
returnList.add(pci);
}
return returnList;
}
public static class PunchCardItem {
private int dayOfWeek;
private int hourOfDay;
private int numberOfCommits;
private PunchCardItem(ArrayList<Integer> item) {
dayOfWeek = item.get(0);
hourOfDay = item.get(1);
numberOfCommits = item.get(2);
}
/**
* @return The day of the week.
* 0 = Sunday, 1 = Monday, etc.
*/
public int getDayOfWeek() {
return dayOfWeek;
}
/**
* @return The hour of the day from 0 to 23.
*/
public long getHourOfDay() {
return hourOfDay;
}
/**
* @return The number of commits for the day and hour.
*/
public long getNumberOfCommits() {
return numberOfCommits;
}
public String toString() {
return "Day " + getDayOfWeek() + " Hour " + getHourOfDay() + ": " +
getNumberOfCommits() + " commits";
}
}
String getApiTailUrl(String tail) {
return repo.getApiTailUrl("stats/" + tail);
}
}

View File

@@ -0,0 +1,54 @@
package org.kohsuke.github;
import java.util.Date;
import java.util.List;
public abstract class GHRepositoryTraffic implements TrafficInfo {
private int count;
private int uniques;
/*package*/ GHRepositoryTraffic() {
}
/*package*/ GHRepositoryTraffic(int count, int uniques) {
this.count = count;
this.uniques = uniques;
}
public int getCount() {
return count;
}
public int getUniques() {
return uniques;
}
public abstract List<? extends DailyInfo> getDailyInfo();
public static abstract class DailyInfo implements TrafficInfo {
private String timestamp;
private int count;
private int uniques;
public Date getTimestamp() {
return GitHub.parseDate(timestamp);
}
public int getCount() {
return count;
}
public int getUniques() {
return uniques;
}
/*package*/ DailyInfo() {
}
/*package*/ DailyInfo(String timestamp, Integer count, Integer uniques) {
this.timestamp = timestamp;
this.count = count;
this.uniques = uniques;
}
}
}

View File

@@ -0,0 +1,37 @@
package org.kohsuke.github;
import java.util.List;
/**
* Repository view statistics.
*
* @see GHRepository#getViewTraffic()
*/
public class GHRepositoryViewTraffic extends GHRepositoryTraffic {
private List<DailyInfo> views;
/*package*/ GHRepositoryViewTraffic() {
}
/*package*/ GHRepositoryViewTraffic(int count, int uniques, List<DailyInfo> views) {
super(count, uniques);
this.views = views;
}
public List<DailyInfo> getViews() {
return views;
}
public List<DailyInfo> getDailyInfo() {
return getViews();
}
public static class DailyInfo extends GHRepositoryTraffic.DailyInfo {
/*package*/ DailyInfo() {
}
/*package*/ DailyInfo(String timestamp, int count, int uniques) {
super(timestamp, count, uniques);
}
}
}

View File

@@ -1,6 +1,6 @@
package org.kohsuke.github;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
@@ -10,9 +10,7 @@ import java.util.List;
*
* @author Kohsuke Kawaguchi
*/
public abstract class GHSearchBuilder<T> {
protected final GitHub root;
protected final Requester req;
public abstract class GHSearchBuilder<T> extends GHQueryBuilder<T> {
protected final List<String> terms = new ArrayList<String>();
/**
@@ -21,15 +19,14 @@ public abstract class GHSearchBuilder<T> {
private final Class<? extends SearchResult<T>> receiverType;
/*package*/ GHSearchBuilder(GitHub root, Class<? extends SearchResult<T>> receiverType) {
this.root = root;
this.req = root.retrieve();
super(root);
this.receiverType = receiverType;
}
/**
* Search terms.
*/
public GHSearchBuilder q(String term) {
public GHQueryBuilder<T> q(String term) {
terms.add(term);
return this;
}
@@ -37,11 +34,12 @@ public abstract class GHSearchBuilder<T> {
/**
* Performs the search.
*/
@Override
public PagedSearchIterable<T> list() {
return new PagedSearchIterable<T>(root) {
public PagedIterator<T> iterator() {
public PagedIterator<T> _iterator(int pageSize) {
req.set("q", StringUtils.join(terms, " "));
return new PagedIterator<T>(adapt(req.asIterator(getApiUrl(), receiverType))) {
return new PagedIterator<T>(adapt(req.asIterator(getApiUrl(), receiverType, pageSize))) {
protected void wrapUp(T[] page) {
// SearchResult.getItems() should do it
}

View File

@@ -0,0 +1,51 @@
package org.kohsuke.github;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Date;
/**
* A stargazer at a repository on GitHub.
*
* @author noctarius
*/
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD"}, justification = "JSON API")
public class GHStargazer {
private GHRepository repository;
private String starred_at;
private GHUser user;
/**
* Gets the repository that is stargazed
*
* @return the starred repository
*/
public GHRepository getRepository() {
return repository;
}
/**
* Gets the date when the repository was starred, however old stars before
* August 2012, will all show the date the API was changed to support starred_at.
*
* @return the date the stargazer was added
*/
public Date getStarredAt() {
return GitHub.parseDate(starred_at);
}
/**
* Gets the user that starred the repository
*
* @return the stargazer user
*/
public GHUser getUser() {
return user;
}
void wrapUp(GHRepository repository) {
this.repository = repository;
user.wrapUp(repository.root);
}
}

View File

@@ -49,7 +49,7 @@ public class GHSubscription {
* Removes this subscription.
*/
public void delete() throws IOException {
new Requester(root).method("DELETE").to(url);
new Requester(root).method("DELETE").to(repo.getApiTailUrl("subscription"));
}
GHSubscription wrapUp(GHRepository repo) {

View File

@@ -0,0 +1,60 @@
package org.kohsuke.github;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* Represents an annotated tag in a {@link GHRepository}
*
* @see GHRepository#getTagObject(String)
*/
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
public class GHTagObject {
private GHRepository owner;
private GitHub root;
private String tag;
private String sha;
private String url;
private String message;
private GitUser tagger;
private GHRef.GHObject object;
/*package*/ GHTagObject wrap(GHRepository owner) {
this.owner = owner;
this.root = owner.root;
return this;
}
public GHRepository getOwner() {
return owner;
}
public GitHub getRoot() {
return root;
}
public String getTag() {
return tag;
}
public String getSha() {
return sha;
}
public String getUrl() {
return url;
}
public String getMessage() {
return message;
}
public GitUser getTagger() {
return tagger;
}
public GHRef.GHObject getObject() {
return object;
}
}

View File

@@ -0,0 +1,24 @@
package org.kohsuke.github;
import org.apache.commons.lang3.StringUtils;
import java.util.Locale;
/**
* App installation target type.
*
* @author Paulo Miguel Almeida
*
* @see GHAppInstallation
*/
public enum GHTargetType {
ORGANIZATION,
USER;
/**
* Returns GitHub's internal representation of this event.
*/
String symbol() {
return StringUtils.capitalize(name().toLowerCase(Locale.ENGLISH));
}
}

View File

@@ -11,15 +11,28 @@ import java.util.TreeMap;
*
* @author Kohsuke Kawaguchi
*/
public class GHTeam {
private String name,permission;
public class GHTeam implements Refreshable {
private String name,permission,slug,description;
private int id;
private GHOrganization organization; // populated by GET /user/teams where Teams+Orgs are returned together
protected /*final*/ GHOrganization org;
protected /*final*/ GitHub root;
/** Member's role in a team */
public enum Role {
/**
* A normal member of the team
*/
MEMBER,
/**
* Able to add/remove other team members, promote other team members to team maintainer, and edit the team's name and description.
*/
MAINTAINER
}
/*package*/ GHTeam wrapUp(GHOrganization owner) {
this.org = owner;
this.organization = owner;
this.root = owner.root;
return this;
}
@@ -35,6 +48,13 @@ public class GHTeam {
return teams;
}
/*package*/ static GHTeam[] wrapUp(GHTeam[] teams, GHPullRequest owner) {
for (GHTeam t : teams) {
t.root = owner.root;
}
return teams;
}
public String getName() {
return name;
}
@@ -43,6 +63,20 @@ public class GHTeam {
return permission;
}
public String getSlug() {
return slug;
}
public String getDescription() {
return description;
}
public void setDescription(String description) throws IOException {
root.retrieve().method("PATCH")
.with("description", description)
.to(api(""));
}
public int getId() {
return id;
}
@@ -51,16 +85,11 @@ public class GHTeam {
* Retrieves the current members.
*/
public PagedIterable<GHUser> listMembers() throws IOException {
return new PagedIterable<GHUser>() {
public PagedIterator<GHUser> iterator() {
return new PagedIterator<GHUser>(org.root.retrieve().asIterator(api("/members"), GHUser[].class)) {
@Override
protected void wrapUp(GHUser[] page) {
GHUser.wrap(page, org.root);
}
};
}
};
return root.retrieve()
.asPagedIterable(
api("/members"),
GHUser[].class,
item -> item.wrapUp(root) );
}
public Set<GHUser> getMembers() throws IOException {
@@ -72,7 +101,7 @@ public class GHTeam {
*/
public boolean hasMember(GHUser user) {
try {
org.root.retrieve().to("/teams/" + id + "/members/" + user.getLogin());
root.retrieve().to("/teams/" + id + "/members/" + user.getLogin());
return true;
} catch (IOException ignore) {
return false;
@@ -88,17 +117,11 @@ public class GHTeam {
}
public PagedIterable<GHRepository> listRepositories() {
return new PagedIterable<GHRepository>() {
public PagedIterator<GHRepository> iterator() {
return new PagedIterator<GHRepository>(org.root.retrieve().asIterator(api("/repos"), GHRepository[].class)) {
@Override
protected void wrapUp(GHRepository[] page) {
for (GHRepository r : page)
r.wrap(org.root);
}
};
}
};
return root.retrieve()
.asPagedIterable(
api("/repos"),
GHRepository[].class,
item -> item.wrap(root) );
}
/**
@@ -109,29 +132,64 @@ public class GHTeam {
* @since 1.59
*/
public void add(GHUser u) throws IOException {
org.root.retrieve().method("PUT").to(api("/memberships/" + u.getLogin()), null);
root.retrieve().method("PUT").to(api("/memberships/" + u.getLogin()), null);
}
/**
* Adds a member to the team
*
* The user will be invited to the organization if required.
*
* @param user github user
* @param role role for the new member
*
* @throws IOException
*/
public void add(GHUser user, Role role) throws IOException {
root.retrieve().method("PUT")
.with("role", role)
.to(api("/memberships/" + user.getLogin()), null);
}
/**
* Removes a member to the team.
*/
public void remove(GHUser u) throws IOException {
org.root.retrieve().method("DELETE").to(api("/members/" + u.getLogin()), null);
root.retrieve().method("DELETE").to(api("/members/" + u.getLogin()), null);
}
public void add(GHRepository r) throws IOException {
org.root.retrieve().method("PUT").to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
add(r,null);
}
public void add(GHRepository r, GHOrganization.Permission permission) throws IOException {
root.retrieve().method("PUT")
.with("permission", permission)
.to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
}
public void remove(GHRepository r) throws IOException {
org.root.retrieve().method("DELETE").to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
root.retrieve().method("DELETE").to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
}
/**
* Deletes this team.
*/
public void delete() throws IOException {
root.retrieve().method("DELETE").to(api(""));
}
private String api(String tail) {
return "/teams/"+id+tail;
return "/teams/" + id + tail;
}
public GHOrganization getOrganization() {
return org;
public GHOrganization getOrganization() throws IOException {
refresh(organization);
return organization;
}
@Override
public void refresh() throws IOException {
root.retrieve().to(api(""), this).wrapUp(root);
}
}

View File

@@ -1,6 +1,7 @@
package org.kohsuke.github;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;

View File

@@ -10,10 +10,12 @@ import java.util.List;
* https://developer.github.com/v3/git/trees/
*
* @author Daniel Teixeira - https://github.com/ddtxra
* @see GHCommit#getTree()
* @see GHRepository#getTree(String)
* @see GHTreeEntry#asTree()
*/
public class GHTree {
/* package almost final */GitHub root;
/* package almost final */GHRepository repo;
private boolean truncated;
private String sha, url;
@@ -28,12 +30,24 @@ public class GHTree {
/**
* Return an array of entries of the trees
* @return
*/
public List<GHTreeEntry> getTree() {
return Collections.unmodifiableList(Arrays.asList(tree));
}
/**
* Finds a tree entry by its name.
*
* IOW, find a directory entry by a file name.
*/
public GHTreeEntry getEntry(String path) {
for (GHTreeEntry e : tree) {
if (e.getPath().equals(path))
return e;
}
return null;
}
/**
* Returns true if the number of items in the tree array exceeded the GitHub maximum limit.
* @return true true if the number of items in the tree array exceeded the GitHub maximum limit otherwise false.
@@ -50,8 +64,11 @@ public class GHTree {
return GitHub.parseURL(url);
}
/* package */GHTree wrap(GitHub root) {
this.root = root;
/* package */GHTree wrap(GHRepository repo) {
this.repo = repo;
for (GHTreeEntry e : tree) {
e.tree = this;
}
return this;
}

View File

@@ -0,0 +1,90 @@
package org.kohsuke.github;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Builder pattern for creating a new tree.
* Based on https://developer.github.com/v3/git/trees/#create-a-tree
*/
public class GHTreeBuilder {
private final GHRepository repo;
private final Requester req;
private final List<TreeEntry> treeEntries = new ArrayList<TreeEntry>();
@SuppressFBWarnings("URF_UNREAD_FIELD")
private static final class TreeEntry {
private final String path;
private final String mode;
private final String type;
private String sha;
private String content;
private TreeEntry(String path, String mode, String type) {
this.path = path;
this.mode = mode;
this.type = type;
}
}
GHTreeBuilder(GHRepository repo) {
this.repo = repo;
req = new Requester(repo.root);
}
/**
* @param baseTree the SHA of tree you want to update with new data
*/
public GHTreeBuilder baseTree(String baseTree) {
req.with("base_tree", baseTree);
return this;
}
/**
* Adds a new entry to the tree.
* Exactly one of the parameters {@code sha} and {@code content} must be non-null.
*/
public GHTreeBuilder entry(String path, String mode, String type, String sha, String content) {
TreeEntry entry = new TreeEntry(path, mode, type);
entry.sha = sha;
entry.content = content;
treeEntries.add(entry);
return this;
}
/**
* Specialized version of {@link #entry(String, String, String, String, String)} for adding an existing blob referred by its SHA.
*/
public GHTreeBuilder shaEntry(String path, String sha, boolean executable) {
TreeEntry entry = new TreeEntry(path, executable ? "100755" : "100644", "blob");
entry.sha = sha;
treeEntries.add(entry);
return this;
}
/**
* Specialized version of {@link #entry(String, String, String, String, String)} for adding a text file with the specified {@code content}.
*/
public GHTreeBuilder textEntry(String path, String content, boolean executable) {
TreeEntry entry = new TreeEntry(path, executable ? "100755" : "100644", "blob");
entry.content = content;
treeEntries.add(entry);
return this;
}
private String getApiTail() {
return String.format("/repos/%s/%s/git/trees", repo.getOwnerName(), repo.getName());
}
/**
* Creates a tree based on the parameters specified thus far.
*/
public GHTree create() throws IOException {
req._with("tree", treeEntries);
return req.method("POST").to(getApiTail(), GHTree.class).wrap(repo);
}
}

View File

@@ -1,5 +1,7 @@
package org.kohsuke.github;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
/**
@@ -10,6 +12,8 @@ import java.net.URL;
* @see GHTree
*/
public class GHTreeEntry {
/* package almost final */GHTree tree;
private String path, mode, type, sha, url;
private long size;
@@ -44,7 +48,7 @@ public class GHTreeEntry {
/**
* Gets the type such as:
* "blob"
* "blob", "tree", etc.
*
* @return The type
*/
@@ -68,4 +72,37 @@ public class GHTreeEntry {
public URL getUrl() {
return GitHub.parseURL(url);
}
/**
* If this tree entry represents a file, then return its information.
* Otherwise null.
*/
public GHBlob asBlob() throws IOException {
if (type.equals("blob"))
return tree.repo.getBlob(sha);
else
return null;
}
/**
* If this tree entry represents a file, then return its content.
* Otherwise null.
*/
public InputStream readAsBlob() throws IOException {
if (type.equals("blob"))
return tree.repo.readBlob(sha);
else
return null;
}
/**
* If this tree entry represents a directory, then return it.
* Otherwise null.
*/
public GHTree asTree() throws IOException {
if (type.equals("tree"))
return tree.repo.getTree(sha);
else
return null;
}
}

Some files were not shown because too many files have changed in this diff Show More