mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-11 08:21:23 +00:00
Compare commits
145 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6606b5c7d1 | ||
|
|
551dbf2a06 | ||
|
|
d734237788 | ||
|
|
47e2a5aea1 | ||
|
|
57cdc308e8 | ||
|
|
8919c5f8c7 | ||
|
|
b8f00bc699 | ||
|
|
042038f480 | ||
|
|
fb03e749bd | ||
|
|
e522239832 | ||
|
|
ae69324196 | ||
|
|
5194c2d9bc | ||
|
|
daf5c5eb98 | ||
|
|
a7b4c97020 | ||
|
|
420d5d06f3 | ||
|
|
a7cd052b7c | ||
|
|
6e1b943823 | ||
|
|
8a3559ada5 | ||
|
|
ea3cbd4c71 | ||
|
|
34a1f9d6e4 | ||
|
|
629bd510c1 | ||
|
|
40937a5cc6 | ||
|
|
8509957102 | ||
|
|
b0aea0c575 | ||
|
|
1f7f646bec | ||
|
|
a59ee6a82d | ||
|
|
1fefc77582 | ||
|
|
199eee4e25 | ||
|
|
854df5321b | ||
|
|
bd509070ac | ||
|
|
a8c7c97d06 | ||
|
|
6d86cfb4f6 | ||
|
|
fb3e956502 | ||
|
|
9b0dbe6f34 | ||
|
|
c10c7237a7 | ||
|
|
36612fe97f | ||
|
|
18e2056a10 | ||
|
|
8c8f1451d4 | ||
|
|
be67f1d9e2 | ||
|
|
90bc250269 | ||
|
|
1bd178654f | ||
|
|
f22bf160f9 | ||
|
|
4261c42949 | ||
|
|
40cfb85a8e | ||
|
|
f08299b134 | ||
|
|
a04ab45abc | ||
|
|
0647df2d2b | ||
|
|
d4cc3af1e9 | ||
|
|
936ab499ce | ||
|
|
453f475b4e | ||
|
|
bda3855b86 | ||
|
|
772a6c112b | ||
|
|
9b4134cada | ||
|
|
ed9f54006d | ||
|
|
3b1f176544 | ||
|
|
d2732bcf54 | ||
|
|
a1461f401a | ||
|
|
f9fd30275c | ||
|
|
eeea14dab4 | ||
|
|
1df807a198 | ||
|
|
0848287069 | ||
|
|
334b37a256 | ||
|
|
8776a3b672 | ||
|
|
657550f767 | ||
|
|
45a0114f75 | ||
|
|
a8ddd3e12a | ||
|
|
b668396151 | ||
|
|
9e7c33369c | ||
|
|
8943ca6d1a | ||
|
|
b3460c1f9d | ||
|
|
5166c9265f | ||
|
|
35c8cfa01d | ||
|
|
8e6dbf3772 | ||
|
|
cb381dfa06 | ||
|
|
80124e3b85 | ||
|
|
7aae27e36f | ||
|
|
b212956fbb | ||
|
|
d033355e84 | ||
|
|
59d7a117d0 | ||
|
|
dfbb38c5f1 | ||
|
|
3f9954144a | ||
|
|
1b84efdbfa | ||
|
|
c33e78a7dc | ||
|
|
747c759bbb | ||
|
|
e0a709676e | ||
|
|
a96275c286 | ||
|
|
ca7c809feb | ||
|
|
a8a0bcb7db | ||
|
|
0e2bf23830 | ||
|
|
44a8b797fb | ||
|
|
cdede298a9 | ||
|
|
f6ac4d3559 | ||
|
|
7e1531dbca | ||
|
|
9aeb422157 | ||
|
|
fba0f8cf8e | ||
|
|
0f4a5227e1 | ||
|
|
d16a752b43 | ||
|
|
4d9aed90d6 | ||
|
|
4bec27fd49 | ||
|
|
f1720b7bbc | ||
|
|
7a79a18d8f | ||
|
|
472034c950 | ||
|
|
b50ab56f9e | ||
|
|
26d30663c4 | ||
|
|
ffecc390eb | ||
|
|
aae5c56a31 | ||
|
|
6670446037 | ||
|
|
bd39b07bb5 | ||
|
|
a9438b6121 | ||
|
|
f546cf4521 | ||
|
|
43efa78750 | ||
|
|
9e3de43802 | ||
|
|
d7931777bc | ||
|
|
bb48d55bd4 | ||
|
|
610b02968e | ||
|
|
a7112c42df | ||
|
|
8a474a3b00 | ||
|
|
59e18d155e | ||
|
|
ff790eeefb | ||
|
|
97e918da03 | ||
|
|
4f30998873 | ||
|
|
a0fc478a28 | ||
|
|
bb03fd1968 | ||
|
|
0c65f74662 | ||
|
|
29ac2bd4f5 | ||
|
|
0d8b4f32e8 | ||
|
|
83db7f24eb | ||
|
|
5f9976a193 | ||
|
|
9480ef485b | ||
|
|
a9b7432584 | ||
|
|
6d7081910f | ||
|
|
aa96089ab4 | ||
|
|
58ae681417 | ||
|
|
c038e0af5e | ||
|
|
4f9976c0cb | ||
|
|
e308e5ed57 | ||
|
|
7b1b1ca994 | ||
|
|
551be49a1a | ||
|
|
a3888e6902 | ||
|
|
43bb6a0dd8 | ||
|
|
05863acbcd | ||
|
|
0e4cd06137 | ||
|
|
85d2d974e7 | ||
|
|
3f021f9552 | ||
|
|
4688870984 |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.java text eol=lf
|
||||
3
.github/PULL_REQUEST_TEMPLATE.md
vendored
3
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -7,8 +7,7 @@ We love getting PRs, but we hate asking people for the same basic changes every
|
||||
- [ ] Push your changes to a branch other than `master`. Create your PR from that branch.
|
||||
- [ ] Add JavaDocs and other comments
|
||||
- [ ] Write tests that run and pass in CI. See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to capture snapshot data.
|
||||
- [ ] Run `mvn clean compile` locally. This may reformat your code, commit those changes.
|
||||
- [ ] Run `mvn -D enable-ci clean install site` locally. If this command doesn't succeed, your change will not pass CI.
|
||||
- [ ] Run `mvn -D enable-ci clean install site` locally. If this command doesn't succeed, your change will not pass CI.
|
||||
|
||||
# When creating a PR:
|
||||
|
||||
|
||||
34
.github/workflows/maven-build.yml
vendored
34
.github/workflows/maven-build.yml
vendored
@@ -2,14 +2,18 @@ name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
# this is required by spotless for JDK 16+
|
||||
env:
|
||||
JAVA_11_PLUS_MAVEN_OPTS: "--add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: build-only (Java ${{ matrix.java }})
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
java: [ 13 ]
|
||||
java: [ 16 ]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK
|
||||
@@ -17,18 +21,21 @@ jobs:
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
- name: Cached .m2
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v2.1.4
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-maven-
|
||||
- name: Maven Install (skipTests)
|
||||
env:
|
||||
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
|
||||
run: mvn -B install -DskipTests -D enable-ci --file pom.xml
|
||||
site:
|
||||
name: site (Java ${{ matrix.java }})
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
java: [ 8, 11 ]
|
||||
steps:
|
||||
@@ -37,7 +44,7 @@ jobs:
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
- uses: actions/cache@v2
|
||||
- uses: actions/cache@v2.1.4
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
@@ -49,24 +56,37 @@ jobs:
|
||||
name: test (${{ matrix.os }}, Java ${{ matrix.java }})
|
||||
runs-on: ${{ matrix.os }}-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ ubuntu, windows ]
|
||||
java: [ 8, 11, 13, 15-ea ]
|
||||
java: [ 8, 11, 16 ]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
- uses: actions/cache@v2
|
||||
- uses: actions/cache@v2.1.4
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-maven-
|
||||
# JDK 8
|
||||
- name: Maven Install without Code Coverage
|
||||
if: matrix.os == 'windows'
|
||||
if: matrix.os == 'windows' && matrix.java == '8'
|
||||
run: mvn -B install --file pom.xml
|
||||
- name: Maven Install with Code Coverage
|
||||
if: matrix.os != 'windows'
|
||||
if: matrix.os != 'windows' && matrix.java == '8'
|
||||
run: mvn -B install -D enable-ci --file pom.xml
|
||||
# JDK 11+
|
||||
- name: Maven Install without Code Coverage
|
||||
if: matrix.os == 'windows' && matrix.java != '8'
|
||||
env:
|
||||
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
|
||||
run: mvn -B install --file pom.xml
|
||||
- name: Maven Install with Code Coverage
|
||||
if: matrix.os != 'windows' && matrix.java != '8'
|
||||
env:
|
||||
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
|
||||
run: mvn -B install -D enable-ci --file pom.xml
|
||||
|
||||
@@ -21,7 +21,7 @@ Example for a single test case:
|
||||
|
||||
### Setting up credential
|
||||
|
||||
1. Create an OAuth token on github.com
|
||||
1. Create a "Personal access token" on https://github.com/ (`Settings` > `Developer settings` > `Personal access tokens`)
|
||||
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)
|
||||
|
||||
|
||||
161
pom.xml
161
pom.xml
@@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.kohsuke</groupId>
|
||||
<artifactId>github-api</artifactId>
|
||||
<version>1.118</version>
|
||||
<version>1.125</version>
|
||||
<name>GitHub API for Java</name>
|
||||
<url>https://github-api.kohsuke.org/</url>
|
||||
<description>GitHub API for Java</description>
|
||||
@@ -11,7 +11,7 @@
|
||||
<connection>scm:git:git@github.com/hub4j/${project.artifactId}.git</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com/hub4j/${project.artifactId}.git</developerConnection>
|
||||
<url>https://github.com/hub4j/github-api/</url>
|
||||
<tag>github-api-1.118</tag>
|
||||
<tag>github-api-1.125</tag>
|
||||
</scm>
|
||||
|
||||
<distributionManagement>
|
||||
@@ -33,18 +33,20 @@
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spotbugs-maven-plugin.version>4.1.4</spotbugs-maven-plugin.version>
|
||||
<spotbugs.version>4.1.3</spotbugs.version>
|
||||
<spotbugs-maven-plugin.version>4.2.0</spotbugs-maven-plugin.version>
|
||||
<spotbugs.version>4.2.1</spotbugs.version>
|
||||
<spotbugs-maven-plugin.failOnError>true</spotbugs-maven-plugin.failOnError>
|
||||
<hamcrest.version>2.2</hamcrest.version>
|
||||
<okhttp3.version>4.4.1</okhttp3.version>
|
||||
<okio.version>2.5.0</okio.version>
|
||||
<spotless-maven-plugin.goal>apply</spotless-maven-plugin.goal>
|
||||
<!-- Using this as the minimum bar for code coverage. Adding methods without covering them will fail this. -->
|
||||
<jacoco.coverage.target.bundle.method>0.60</jacoco.coverage.target.bundle.method>
|
||||
<jacoco.coverage.target.class.method>0.25</jacoco.coverage.target.class.method>
|
||||
<jacoco.coverage.target.bundle.method>0.70</jacoco.coverage.target.bundle.method>
|
||||
<jacoco.coverage.target.class.method>0.50</jacoco.coverage.target.class.method>
|
||||
<!-- For non-ci builds we'd like the build to still complete if jacoco metrics aren't met. -->
|
||||
<jacoco.haltOnFailure>false</jacoco.haltOnFailure>
|
||||
<jjwt.suite.version>0.11.2</jjwt.suite.version>
|
||||
|
||||
<surefire.argLine />
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
@@ -152,59 +154,39 @@
|
||||
<!-- Sample only -->
|
||||
<exclude>org.kohsuke.github.example.*</exclude>
|
||||
|
||||
<!-- No methods -->
|
||||
<exclude>org.kohsuke.github.Previews</exclude>
|
||||
|
||||
<!-- Deprecated -->
|
||||
<exclude>org.kohsuke.github.extras.OkHttp3Connector</exclude>
|
||||
<exclude>org.kohsuke.github.EnforcementLevel</exclude>
|
||||
<exclude>org.kohsuke.github.GHPerson.1</exclude>
|
||||
|
||||
<!-- These fail coverage on windows because tests are disabled -->
|
||||
<exclude>org.kohsuke.github.GHAsset</exclude>
|
||||
<exclude>org.kohsuke.github.GHReleaseBuilder</exclude>
|
||||
<exclude>org.kohsuke.github.GHRelease</exclude>
|
||||
<!-- TODO: Some coverage, but more needed -->
|
||||
<exclude>org.kohsuke.github.GHPullRequestReviewBuilder.DraftReviewComment</exclude>
|
||||
<exclude>org.kohsuke.github.GHIssue.PullRequest</exclude>
|
||||
<exclude>org.kohsuke.github.GHCommitSearchBuilder</exclude>
|
||||
<exclude>org.kohsuke.github.GHRepositorySearchBuilder</exclude>
|
||||
<exclude>org.kohsuke.github.GHUserSearchBuilder</exclude>
|
||||
|
||||
<!-- TODO: These still need test coverage -->
|
||||
<exclude>org.kohsuke.github.GHBranchProtection.RequiredSignatures</exclude>
|
||||
<exclude>org.kohsuke.github.GHBranchProtectionBuilder.Restrictions</exclude>
|
||||
<exclude>org.kohsuke.github.GHBranchProtection.Restrictions</exclude>
|
||||
<exclude>org.kohsuke.github.GHCommentAuthorAssociation</exclude>
|
||||
<exclude>org.kohsuke.github.GHCommitBuilder.UserInfo</exclude>
|
||||
<exclude>org.kohsuke.github.GHCommitState</exclude>
|
||||
<exclude>org.kohsuke.github.GHCompare.Commit</exclude>
|
||||
<exclude>org.kohsuke.github.GHCompare.InnerCommit</exclude>
|
||||
<exclude>org.kohsuke.github.GHCompare.Status</exclude>
|
||||
<exclude>org.kohsuke.github.GHCompare.Tree</exclude>
|
||||
<exclude>org.kohsuke.github.GHCompare.User</exclude>
|
||||
<exclude>org.kohsuke.github.GHCompare</exclude>
|
||||
<exclude>org.kohsuke.github.GHDeployKey</exclude>
|
||||
<exclude>org.kohsuke.github.GHDeploymentStatusBuilder</exclude>
|
||||
<exclude>org.kohsuke.github.GHDirection</exclude>
|
||||
<exclude>org.kohsuke.github.GHEmail</exclude>
|
||||
<exclude>org.kohsuke.github.GHEventPayload.Ping</exclude>
|
||||
<exclude>org.kohsuke.github.GHEventPayload.Release</exclude>
|
||||
<exclude>org.kohsuke.github.GHException</exclude>
|
||||
<exclude>org.kohsuke.github.GHHook</exclude>
|
||||
<exclude>org.kohsuke.github.GHHooks.OrgContext</exclude>
|
||||
<exclude>org.kohsuke.github.GHInvitation</exclude>
|
||||
<exclude>org.kohsuke.github.GHMilestoneState</exclude>
|
||||
<exclude>org.kohsuke.github.GHOrgHook</exclude>
|
||||
<exclude>org.kohsuke.github.GHProject.ProjectStateFilter</exclude>
|
||||
<exclude>org.kohsuke.github.GHPullRequestCommitDetail.Authorship</exclude>
|
||||
<exclude>org.kohsuke.github.GHPullRequestCommitDetail.Commit</exclude>
|
||||
<exclude>org.kohsuke.github.GHPullRequestCommitDetail.CommitPointer</exclude>
|
||||
<exclude>org.kohsuke.github.GHPullRequestCommitDetail.Tree</exclude>
|
||||
<exclude>org.kohsuke.github.GHPullRequestCommitDetail</exclude>
|
||||
<exclude>org.kohsuke.github.GHPullRequestFileDetail</exclude>
|
||||
<exclude>org.kohsuke.github.GHPullRequestQueryBuilder.Sort</exclude>
|
||||
<exclude>org.kohsuke.github.GHReleaseUpdater</exclude>
|
||||
<exclude>org.kohsuke.github.GHRepository.ForkSort</exclude>
|
||||
<exclude>org.kohsuke.github.GHRequestedAction</exclude>
|
||||
<exclude>org.kohsuke.github.GHStargazer</exclude>
|
||||
<exclude>org.kohsuke.github.GHTagObject</exclude>
|
||||
<exclude>org.kohsuke.github.GHTeam.Role</exclude>
|
||||
<exclude>org.kohsuke.github.GHUserSearchBuilder.Sort</exclude>
|
||||
<exclude>org.kohsuke.github.GHVerifiedKey</exclude>
|
||||
</excludes>
|
||||
</rule>
|
||||
@@ -292,18 +274,7 @@
|
||||
<id>default-test</id>
|
||||
<configuration>
|
||||
<excludesFile>src/test/resources/slow-or-flaky-tests.txt</excludesFile>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>slow-or-flaky-test</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rerunFailingTestsCount>2</rerunFailingTestsCount>
|
||||
<!-- There are some tests that take longer or are a little flaky. Run them here. -->
|
||||
<includesFile>src/test/resources/slow-or-flaky-tests.txt</includesFile>
|
||||
<argLine>${surefire.argLine}</argLine>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
@@ -311,7 +282,7 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>animal-sniffer-maven-plugin</artifactId>
|
||||
<version>1.19</version>
|
||||
<version>1.20</version>
|
||||
<configuration>
|
||||
<signature>
|
||||
<groupId>org.codehaus.mojo.signature</groupId>
|
||||
@@ -344,13 +315,14 @@
|
||||
<plugin>
|
||||
<groupId>com.diffplug.spotless</groupId>
|
||||
<artifactId>spotless-maven-plugin</artifactId>
|
||||
<version>2.6.1</version>
|
||||
<version>2.8.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>spotless-check</id>
|
||||
<phase>process-sources</phase>
|
||||
<!-- runs in verify phase by default -->
|
||||
<goals>
|
||||
<goal>${spotless-maven-plugin.goal}</goal>
|
||||
<!-- can be disabled using -Dspotless.check.skip=true -->
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
@@ -409,7 +381,7 @@
|
||||
<dependency>
|
||||
<groupId>com.tngtech.archunit</groupId>
|
||||
<artifactId>archunit</artifactId>
|
||||
<version>0.15.0</version>
|
||||
<version>0.17.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -434,13 +406,19 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<version>4.0.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.10.2</version>
|
||||
<version>2.12.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
@@ -489,20 +467,20 @@
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
<version>0.11.2</version>
|
||||
<scope>test</scope>
|
||||
<version>${jjwt.suite.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
<version>0.11.2</version>
|
||||
<scope>test</scope>
|
||||
<version>${jjwt.suite.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
<version>0.11.2</version>
|
||||
<scope>test</scope>
|
||||
<version>${jjwt.suite.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okio</groupId>
|
||||
@@ -539,7 +517,7 @@
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>3.6.28</version>
|
||||
<version>3.7.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -580,6 +558,48 @@
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<profiles>
|
||||
<!-- only enable slow-or-flaky-test if -Dtest= is not present -->
|
||||
<profile>
|
||||
<id>slow-or-flaky-test</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>!test</name>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>slow-or-flaky-test</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rerunFailingTestsCount>2</rerunFailingTestsCount>
|
||||
<!-- There are some tests that take longer or are a little
|
||||
flaky. Run them here. -->
|
||||
<includesFile>src/test/resources/slow-or-flaky-tests.txt</includesFile>
|
||||
<argLine>${surefire.argLine}</argLine>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>jdk11+</id>
|
||||
<activation>
|
||||
<jdk>[11,)</jdk>
|
||||
</activation>
|
||||
<properties>
|
||||
<!-- this is required for GithubHttpUrlConnectionClient#setRequestMethod() to work with JDK 16+ -->
|
||||
<surefire.argLine>--add-opens java.base/java.net=ALL-UNNAMED</surefire.argLine>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>ci-non-windows</id>
|
||||
<activation>
|
||||
@@ -591,7 +611,8 @@
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<spotless-maven-plugin.goal>check</spotless-maven-plugin.goal>
|
||||
<!-- Only fail code coverage on non-windows machines -->
|
||||
<jacoco.haltOnFailure>true</jacoco.haltOnFailure>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
@@ -601,23 +622,31 @@
|
||||
<name>enable-ci</name>
|
||||
</property>
|
||||
</activation>
|
||||
<properties>
|
||||
<jacoco.haltOnFailure>true</jacoco.haltOnFailure>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.diffplug.spotless</groupId>
|
||||
<artifactId>spotless-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>spotless-check</id>
|
||||
<!-- In CI, run check early in the build -->
|
||||
<phase>process-sources</phase>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>release</id>
|
||||
<properties>
|
||||
<spotless-maven-plugin.goal>check</spotless-maven-plugin.goal>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.kohsuke.github.Previews.MACHINE_MAN;
|
||||
import static org.kohsuke.github.internal.Previews.MACHINE_MAN;
|
||||
|
||||
/**
|
||||
* A Github App.
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.kohsuke.github.Previews.MACHINE_MAN;
|
||||
import static org.kohsuke.github.internal.Previews.MACHINE_MAN;
|
||||
|
||||
/**
|
||||
* Creates a access token for a GitHub App Installation
|
||||
|
||||
@@ -8,8 +8,8 @@ import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.kohsuke.github.Previews.GAMBIT;
|
||||
import static org.kohsuke.github.Previews.MACHINE_MAN;
|
||||
import static org.kohsuke.github.internal.Previews.GAMBIT;
|
||||
import static org.kohsuke.github.internal.Previews.MACHINE_MAN;
|
||||
|
||||
/**
|
||||
* A Github App Installation.
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.kohsuke.github;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.kohsuke.github.internal.Previews;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
@@ -6,7 +6,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.kohsuke.github.Previews.ZZZAX;
|
||||
import static org.kohsuke.github.internal.Previews.ZZZAX;
|
||||
|
||||
/**
|
||||
* The type GHBranchProtection.
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.kohsuke.github.Previews.*;
|
||||
import static org.kohsuke.github.internal.Previews.LUKE_CAGE;
|
||||
|
||||
/**
|
||||
* Builder to configure the branch protection settings.
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.kohsuke.github.GHWorkflowRun.Conclusion;
|
||||
import org.kohsuke.github.GHWorkflowRun.Status;
|
||||
import org.kohsuke.github.internal.EnumUtils;
|
||||
import org.kohsuke.github.internal.Previews;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
@@ -10,6 +15,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Represents a check run.
|
||||
@@ -79,12 +85,27 @@ public class GHCheckRun extends GHObject {
|
||||
* @return Status of the check run
|
||||
* @see Status
|
||||
*/
|
||||
public String getStatus() {
|
||||
@WithBridgeMethods(value = String.class, adapterMethod = "statusAsStr")
|
||||
public Status getStatus() {
|
||||
return Status.from(status);
|
||||
}
|
||||
|
||||
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getStatus")
|
||||
private Object statusAsStr(Status status, Class type) {
|
||||
return status;
|
||||
}
|
||||
|
||||
public static enum Status {
|
||||
QUEUED, IN_PROGRESS, COMPLETED
|
||||
QUEUED, IN_PROGRESS, COMPLETED, UNKNOWN;
|
||||
|
||||
public static Status from(String value) {
|
||||
return EnumUtils.getNullableEnumOrDefault(Status.class, value, Status.UNKNOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +114,13 @@ public class GHCheckRun extends GHObject {
|
||||
* @return Status of the check run
|
||||
* @see Conclusion
|
||||
*/
|
||||
public String getConclusion() {
|
||||
@WithBridgeMethods(value = String.class, adapterMethod = "conclusionAsStr")
|
||||
public Conclusion getConclusion() {
|
||||
return Conclusion.from(conclusion);
|
||||
}
|
||||
|
||||
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getConclusion")
|
||||
private Object conclusionAsStr(Conclusion conclusion, Class type) {
|
||||
return conclusion;
|
||||
}
|
||||
|
||||
@@ -104,7 +131,16 @@ public class GHCheckRun extends GHObject {
|
||||
* Parameters - <code>conclusion</code></a>.
|
||||
*/
|
||||
public static enum Conclusion {
|
||||
SUCCESS, FAILURE, NEUTRAL, CANCELLED, TIMED_OUT, ACTION_REQUIRED, SKIPPED
|
||||
ACTION_REQUIRED, CANCELLED, FAILURE, NEUTRAL, SUCCESS, SKIPPED, STALE, TIMED_OUT, UNKNOWN;
|
||||
|
||||
public static Conclusion from(String value) {
|
||||
return EnumUtils.getNullableEnumOrDefault(Conclusion.class, value, Conclusion.UNKNOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import edu.umd.cs.findbugs.annotations.CheckForNull;
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.kohsuke.github.internal.Previews;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
@@ -151,7 +152,7 @@ public final class GHCheckRunBuilder {
|
||||
}
|
||||
GHCheckRun run = requester.with("output", output).with("actions", actions).fetch(GHCheckRun.class).wrap(repo);
|
||||
while (!extraAnnotations.isEmpty()) {
|
||||
Output output2 = new Output(output.title, output.summary);
|
||||
Output output2 = new Output(output.title, output.summary).withText(output.text);
|
||||
int i = Math.min(extraAnnotations.size(), MAX_ANNOTATIONS);
|
||||
output2.annotations = extraAnnotations.subList(0, i);
|
||||
extraAnnotations = extraAnnotations.subList(i, extraAnnotations.size());
|
||||
|
||||
@@ -11,8 +11,8 @@ import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.kohsuke.github.Previews.ANTIOPE;
|
||||
import static org.kohsuke.github.Previews.GROOT;
|
||||
import static org.kohsuke.github.internal.Previews.ANTIOPE;
|
||||
import static org.kohsuke.github.internal.Previews.GROOT;
|
||||
|
||||
/**
|
||||
* A commit in a repository.
|
||||
|
||||
@@ -5,7 +5,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import static org.kohsuke.github.Previews.*;
|
||||
import static org.kohsuke.github.internal.Previews.SQUIRREL_GIRL;
|
||||
|
||||
/**
|
||||
* A comment attached to a commit (or a specific line in a specific file of a commit.)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.kohsuke.github.internal.Previews;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.kohsuke.github;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.kohsuke.github.Previews.BAPTISTE;
|
||||
import static org.kohsuke.github.internal.Previews.BAPTISTE;
|
||||
|
||||
/**
|
||||
* Creates a repository
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.kohsuke.github.internal.Previews;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.kohsuke.github.internal.Previews;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.kohsuke.github.internal.Previews;
|
||||
|
||||
/**
|
||||
* Represents the state of deployment
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.kohsuke.github.internal.Previews;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.kohsuke.github.internal.Previews;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.kohsuke.github.internal.Previews;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.util.Locale;
|
||||
public enum GHEvent {
|
||||
CHECK_RUN,
|
||||
CHECK_SUITE,
|
||||
CODE_SCANNING_ALERT,
|
||||
COMMIT_COMMENT,
|
||||
CONTENT_REFERENCE,
|
||||
CREATE,
|
||||
|
||||
@@ -5,7 +5,9 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Base type for types used in databinding of the event payload.
|
||||
@@ -380,9 +382,9 @@ public class GHEventPayload extends GitHubInteractiveObject {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets label.
|
||||
* Gets the added or removed label for labeled/unlabeled events.
|
||||
*
|
||||
* @return the label
|
||||
* @return label the added or removed label
|
||||
*/
|
||||
public GHLabel getLabel() {
|
||||
return label;
|
||||
@@ -519,6 +521,10 @@ public class GHEventPayload extends GitHubInteractiveObject {
|
||||
public static class Issue extends GHEventPayload {
|
||||
private GHIssue issue;
|
||||
|
||||
private GHLabel label;
|
||||
|
||||
private GHIssueChanges changes;
|
||||
|
||||
/**
|
||||
* Gets issue.
|
||||
*
|
||||
@@ -538,6 +544,24 @@ public class GHEventPayload extends GitHubInteractiveObject {
|
||||
this.issue = issue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the added or removed label for labeled/unlabeled events.
|
||||
*
|
||||
* @return label the added or removed label
|
||||
*/
|
||||
public GHLabel getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get changes (for action="edited")
|
||||
*
|
||||
* @return changes
|
||||
*/
|
||||
public GHIssueChanges getChanges() {
|
||||
return changes;
|
||||
}
|
||||
|
||||
@Override
|
||||
void wrapUp(GitHub root) {
|
||||
super.wrapUp(root);
|
||||
@@ -1067,7 +1091,7 @@ public class GHEventPayload extends GitHubInteractiveObject {
|
||||
public static class PushCommit {
|
||||
private GitUser author;
|
||||
private GitUser committer;
|
||||
private String url, sha, message;
|
||||
private String url, sha, message, timestamp;
|
||||
private boolean distinct;
|
||||
private List<String> added, removed, modified;
|
||||
|
||||
@@ -1156,6 +1180,15 @@ public class GHEventPayload extends GitHubInteractiveObject {
|
||||
public List<String> getModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the timestamp of the commit
|
||||
*
|
||||
* @return the timestamp
|
||||
*/
|
||||
public Date getTimestamp() {
|
||||
return GitHubClient.parseDate(timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1294,4 +1327,86 @@ public class GHEventPayload extends GitHubInteractiveObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurs when someone triggered a workflow run or sends a POST request to the "Create a workflow dispatch event"
|
||||
* endpoint.
|
||||
*
|
||||
* @see <a href=
|
||||
* "https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#workflow_dispatch">
|
||||
* workflow dispatch event</a>
|
||||
* @see <a href=
|
||||
* "https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch">Events that
|
||||
* trigger workflows</a>
|
||||
*/
|
||||
public static class WorkflowDispatch extends GHEventPayload {
|
||||
private Map<String, Object> inputs;
|
||||
private String ref;
|
||||
private String workflow;
|
||||
|
||||
/**
|
||||
* Gets the map of input parameters passed to the workflow.
|
||||
*
|
||||
* @return the map of input parameters
|
||||
*/
|
||||
public Map<String, Object> getInputs() {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ref of the branch (e.g. refs/heads/main)
|
||||
*
|
||||
* @return the ref of the branch
|
||||
*/
|
||||
public String getRef() {
|
||||
return ref;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path of the workflow file (e.g. .github/workflows/hello-world-workflow.yml).
|
||||
*
|
||||
* @return the path of the workflow file
|
||||
*/
|
||||
public String getWorkflow() {
|
||||
return workflow;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A workflow run was requested or completed.
|
||||
*
|
||||
* @see <a href=
|
||||
* "https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#workflow_run">
|
||||
* workflow run event</a>
|
||||
* @see <a href="https://docs.github.com/en/rest/reference/actions#workflow-runs">Actions Workflow Runs</a>
|
||||
*/
|
||||
public static class WorkflowRun extends GHEventPayload {
|
||||
private GHWorkflowRun workflowRun;
|
||||
private GHWorkflow workflow;
|
||||
|
||||
public GHWorkflowRun getWorkflowRun() {
|
||||
return workflowRun;
|
||||
}
|
||||
|
||||
public GHWorkflow getWorkflow() {
|
||||
return workflow;
|
||||
}
|
||||
|
||||
@Override
|
||||
void wrapUp(GitHub root) {
|
||||
super.wrapUp(root);
|
||||
if (workflowRun == null || workflow == null) {
|
||||
throw new IllegalStateException(
|
||||
"Expected workflow and workflow_run payload, but got something else. Maybe we've got another type of event?");
|
||||
}
|
||||
GHRepository repository = getRepository();
|
||||
if (repository != null) {
|
||||
workflowRun.wrapUp(repository);
|
||||
workflow.wrapUp(repository);
|
||||
} else {
|
||||
workflowRun.wrapUp(root);
|
||||
workflow.wrapUp(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.kohsuke.github.Previews.SQUIRREL_GIRL;
|
||||
import static org.kohsuke.github.internal.Previews.SQUIRREL_GIRL;
|
||||
|
||||
/**
|
||||
* Represents an issue on GitHub.
|
||||
@@ -312,7 +312,7 @@ public class GHIssue extends GHObject implements Reactable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets labels.
|
||||
* Sets labels on the target to a specific list.
|
||||
*
|
||||
* @param labels
|
||||
* the labels
|
||||
@@ -326,6 +326,8 @@ public class GHIssue extends GHObject implements Reactable {
|
||||
/**
|
||||
* Adds labels to the issue.
|
||||
*
|
||||
* Labels that are already present on the target are ignored.
|
||||
*
|
||||
* @param names
|
||||
* Names of the label
|
||||
* @throws IOException
|
||||
@@ -338,6 +340,8 @@ public class GHIssue extends GHObject implements Reactable {
|
||||
/**
|
||||
* Add labels.
|
||||
*
|
||||
* Labels that are already present on the target are ignored.
|
||||
*
|
||||
* @param labels
|
||||
* the labels
|
||||
* @throws IOException
|
||||
@@ -350,6 +354,8 @@ public class GHIssue extends GHObject implements Reactable {
|
||||
/**
|
||||
* Add labels.
|
||||
*
|
||||
* Labels that are already present on the target are ignored.
|
||||
*
|
||||
* @param labels
|
||||
* the labels
|
||||
* @throws IOException
|
||||
@@ -360,21 +366,27 @@ public class GHIssue extends GHObject implements Reactable {
|
||||
}
|
||||
|
||||
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]));
|
||||
root.createRequest().with("labels", names).method("POST").withUrlPath(getIssuesApiRoute() + "/labels").send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a given label by name from this issue.
|
||||
* Remove a single label.
|
||||
*
|
||||
* Attempting to remove a label that is not present throws {@link GHFileNotFoundException}.
|
||||
*
|
||||
* @param name
|
||||
* the name
|
||||
* @throws IOException
|
||||
* the io exception, throws {@link GHFileNotFoundException} if label was not present.
|
||||
*/
|
||||
public void removeLabel(String name) throws IOException {
|
||||
root.createRequest().method("DELETE").withUrlPath(getIssuesApiRoute() + "/labels", name).send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a collection of labels.
|
||||
*
|
||||
* Attempting to remove labels that are not present on the target are ignored.
|
||||
*
|
||||
* @param names
|
||||
* the names
|
||||
@@ -386,7 +398,9 @@ public class GHIssue extends GHObject implements Reactable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove labels.
|
||||
* Remove a collection of labels.
|
||||
*
|
||||
* Attempting to remove labels that are not present on the target are ignored.
|
||||
*
|
||||
* @param labels
|
||||
* the labels
|
||||
@@ -399,7 +413,9 @@ public class GHIssue extends GHObject implements Reactable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove labels.
|
||||
* Remove a collection of labels.
|
||||
*
|
||||
* Attempting to remove labels that are not present on the target are ignored.
|
||||
*
|
||||
* @param labels
|
||||
* the labels
|
||||
@@ -411,15 +427,13 @@ public class GHIssue extends GHObject implements Reactable {
|
||||
}
|
||||
|
||||
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());
|
||||
for (String name : names) {
|
||||
try {
|
||||
removeLabel(name);
|
||||
} catch (GHFileNotFoundException e) {
|
||||
// when trying to remove multiple labels, we ignore already removed
|
||||
}
|
||||
}
|
||||
|
||||
setLabels(newLabels.toArray(new String[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
49
src/main/java/org/kohsuke/github/GHIssueChanges.java
Normal file
49
src/main/java/org/kohsuke/github/GHIssueChanges.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
/**
|
||||
* Wrapper to define changed fields on issues action="edited"
|
||||
*
|
||||
* @see GHEventPayload.Issue
|
||||
*/
|
||||
@SuppressFBWarnings("UWF_UNWRITTEN_FIELD")
|
||||
public class GHIssueChanges {
|
||||
|
||||
private GHFrom title;
|
||||
private GHFrom body;
|
||||
|
||||
/**
|
||||
* Old issue title.
|
||||
*
|
||||
* @return old issue title (or null if not changed)
|
||||
*/
|
||||
public GHFrom getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Old issue body.
|
||||
*
|
||||
* @return old issue body (or null if not changed)
|
||||
*/
|
||||
public GHFrom getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for changed values.
|
||||
*/
|
||||
public static class GHFrom {
|
||||
private String from;
|
||||
|
||||
/**
|
||||
* Previous value that was changed.
|
||||
*
|
||||
* @return previous value
|
||||
*/
|
||||
public String getFrom() {
|
||||
return from;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ package org.kohsuke.github;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import static org.kohsuke.github.Previews.*;
|
||||
import static org.kohsuke.github.internal.Previews.SQUIRREL_GIRL;
|
||||
|
||||
/**
|
||||
* Comment to the issue
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.kohsuke.github;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JacksonInject;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -22,6 +23,11 @@ import javax.annotation.Nonnull;
|
||||
*/
|
||||
public class GHLabel extends GitHubInteractiveObject {
|
||||
|
||||
private long id;
|
||||
private String nodeId;
|
||||
@JsonProperty("default")
|
||||
private boolean default_;
|
||||
|
||||
@Nonnull
|
||||
private String url, name, color;
|
||||
|
||||
@@ -42,6 +48,24 @@ public class GHLabel extends GitHubInteractiveObject {
|
||||
return Objects.requireNonNull(root);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets node id.
|
||||
*
|
||||
* @return the node id.
|
||||
*/
|
||||
public String getNodeId() {
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets url.
|
||||
*
|
||||
@@ -82,6 +106,15 @@ public class GHLabel extends GitHubInteractiveObject {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the label is one of the default labels created by GitHub automatically.
|
||||
*
|
||||
* @return true if the label is a default one
|
||||
*/
|
||||
public boolean isDefault() {
|
||||
return default_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets color.
|
||||
*
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static org.kohsuke.github.Previews.INERTIA;
|
||||
import static org.kohsuke.github.internal.Previews.INERTIA;
|
||||
|
||||
/**
|
||||
* The type GHOrganization.
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.kohsuke.github.Previews.INERTIA;
|
||||
import static org.kohsuke.github.internal.Previews.INERTIA;
|
||||
|
||||
/**
|
||||
* A GitHub project.
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import static org.kohsuke.github.Previews.INERTIA;
|
||||
import static org.kohsuke.github.internal.Previews.INERTIA;
|
||||
|
||||
/**
|
||||
* The type GHProjectCard.
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import static org.kohsuke.github.Previews.INERTIA;
|
||||
import static org.kohsuke.github.internal.Previews.INERTIA;
|
||||
|
||||
/**
|
||||
* The type GHProjectColumn.
|
||||
|
||||
@@ -36,8 +36,8 @@ import java.util.Objects;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
|
||||
import static org.kohsuke.github.Previews.LYDIAN;
|
||||
import static org.kohsuke.github.Previews.SHADOW_CAT;
|
||||
import static org.kohsuke.github.internal.Previews.LYDIAN;
|
||||
import static org.kohsuke.github.internal.Previews.SHADOW_CAT;
|
||||
|
||||
/**
|
||||
* A pull request.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import static org.kohsuke.github.Previews.SHADOW_CAT;
|
||||
import static org.kohsuke.github.internal.Previews.SHADOW_CAT;
|
||||
|
||||
/**
|
||||
* Lists up pull requests with some filtering and sorting.
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.net.URL;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
|
||||
import static org.kohsuke.github.Previews.*;
|
||||
import static org.kohsuke.github.internal.Previews.SQUIRREL_GIRL;
|
||||
|
||||
/**
|
||||
* Review comment to the pull request
|
||||
@@ -153,7 +153,20 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
||||
* @return the api route
|
||||
*/
|
||||
protected String getApiRoute() {
|
||||
return "/repos/" + owner.getRepository().getFullName() + "/pulls/comments/" + getId();
|
||||
return getApiRoute(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets api route.
|
||||
*
|
||||
* @param includePullNumber
|
||||
* if true, includes the owning pull request's number in the route.
|
||||
*
|
||||
* @return the api route
|
||||
*/
|
||||
protected String getApiRoute(boolean includePullNumber) {
|
||||
return "/repos/" + owner.getRepository().getFullName() + "/pulls"
|
||||
+ (includePullNumber ? "/" + owner.getNumber() : "") + "/comments/" + getId();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,8 +205,7 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
||||
return owner.root.createRequest()
|
||||
.method("POST")
|
||||
.with("body", body)
|
||||
.with("in_reply_to", getId())
|
||||
.withUrlPath(getApiRoute() + "/comments")
|
||||
.withUrlPath(getApiRoute(true) + "/replies")
|
||||
.fetch(GHPullRequestReviewComment.class)
|
||||
.wrapUp(owner);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.kohsuke.github;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import static org.kohsuke.github.Previews.*;
|
||||
import static org.kohsuke.github.internal.Previews.SQUIRREL_GIRL;
|
||||
|
||||
/**
|
||||
* Reaction to issue, comment, PR, and so on.
|
||||
|
||||
@@ -30,6 +30,7 @@ import edu.umd.cs.findbugs.annotations.CheckForNull;
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.kohsuke.github.function.InputStreamFunction;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@@ -49,7 +50,6 @@ import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.WeakHashMap;
|
||||
@@ -57,7 +57,8 @@ import java.util.WeakHashMap;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static org.kohsuke.github.Previews.*;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static org.kohsuke.github.internal.Previews.*;
|
||||
|
||||
/**
|
||||
* A repository on GitHub.
|
||||
@@ -1782,7 +1783,7 @@ public class GHRepository extends GHObject {
|
||||
return root.createRequest()
|
||||
.withHeader("Accept", "application/vnd.github.v3.raw")
|
||||
.withUrlPath(target)
|
||||
.fetchStream();
|
||||
.fetchStream(Requester::copyInputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2809,7 +2810,7 @@ public class GHRepository extends GHObject {
|
||||
.with("mode", mode == null ? null : mode.toString())
|
||||
.with("context", getFullName())
|
||||
.withUrlPath("/markdown")
|
||||
.fetchStream(),
|
||||
.fetchStream(Requester::copyInputStream),
|
||||
"UTF-8");
|
||||
}
|
||||
|
||||
@@ -2897,6 +2898,71 @@ public class GHRepository extends GHObject {
|
||||
.wrapUp(root);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all the workflows of this repository.
|
||||
*
|
||||
* @return the paged iterable
|
||||
*/
|
||||
public PagedIterable<GHWorkflow> listWorkflows() {
|
||||
return root.createRequest()
|
||||
.withUrlPath(getApiTailUrl("actions/workflows"))
|
||||
.toIterable(GHWorkflow[].class, item -> item.wrapUp(root));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a workflow by id.
|
||||
*
|
||||
* @param id
|
||||
* the id of the workflow run
|
||||
* @return the workflow run
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public GHWorkflow getWorkflow(long id) throws IOException {
|
||||
return getWorkflow(String.valueOf(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a workflow by name of the file.
|
||||
*
|
||||
* @param nameOrId
|
||||
* either the name of the file (e.g. my-workflow.yml) or the id as a string
|
||||
* @return the workflow run
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public GHWorkflow getWorkflow(String nameOrId) throws IOException {
|
||||
return root.createRequest()
|
||||
.withUrlPath(getApiTailUrl("actions/workflows"), nameOrId)
|
||||
.fetch(GHWorkflow.class)
|
||||
.wrapUp(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves workflow runs.
|
||||
*
|
||||
* @return the workflow run query builder
|
||||
*/
|
||||
public GHWorkflowRunQueryBuilder queryWorkflowRuns() {
|
||||
return new GHWorkflowRunQueryBuilder(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a workflow run.
|
||||
*
|
||||
* @param id
|
||||
* the id of the workflow run
|
||||
* @return the workflow run
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public GHWorkflowRun getWorkflowRun(long id) throws IOException {
|
||||
return root.createRequest()
|
||||
.withUrlPath(getApiTailUrl("actions/runs"), String.valueOf(id))
|
||||
.fetch(GHWorkflowRun.class)
|
||||
.wrapUp(this);
|
||||
}
|
||||
|
||||
// Only used within listTopics().
|
||||
private static class Topics {
|
||||
public List<String> names;
|
||||
@@ -2963,6 +3029,52 @@ public class GHRepository extends GHObject {
|
||||
.wrap(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Streams a zip archive of the repository, optionally at a given <code>ref</code>.
|
||||
*
|
||||
* @param <T>
|
||||
* the type of result
|
||||
* @param streamFunction
|
||||
* The {@link InputStreamFunction} that will process the stream
|
||||
* @param ref
|
||||
* if <code>null</code> the repository's default branch, usually <code>master</code>,
|
||||
* @throws IOException
|
||||
* The IO exception.
|
||||
* @return the result of reading the stream.
|
||||
*/
|
||||
public <T> T readZip(InputStreamFunction<T> streamFunction, String ref) throws IOException {
|
||||
return downloadArchive("zip", ref, streamFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Streams a tar archive of the repository, optionally at a given <code>ref</code>.
|
||||
*
|
||||
* @param <T>
|
||||
* the type of result
|
||||
* @param streamFunction
|
||||
* The {@link InputStreamFunction} that will process the stream
|
||||
* @param ref
|
||||
* if <code>null</code> the repository's default branch, usually <code>master</code>,
|
||||
* @throws IOException
|
||||
* The IO exception.
|
||||
* @return the result of reading the stream.
|
||||
*/
|
||||
public <T> T readTar(InputStreamFunction<T> streamFunction, String ref) throws IOException {
|
||||
return downloadArchive("tar", ref, streamFunction);
|
||||
}
|
||||
|
||||
private <T> T downloadArchive(@Nonnull String type,
|
||||
@CheckForNull String ref,
|
||||
@Nonnull InputStreamFunction<T> streamFunction) throws IOException {
|
||||
requireNonNull(streamFunction, "Sink must not be null");
|
||||
String tailUrl = getApiTailUrl(type + "ball");
|
||||
if (ref != null) {
|
||||
tailUrl += "/" + ref;
|
||||
}
|
||||
final Requester builder = root.createRequest().method("GET").withUrlPath(tailUrl);
|
||||
return builder.fetchStream(streamFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate this object.
|
||||
*
|
||||
@@ -2974,7 +3086,7 @@ public class GHRepository extends GHObject {
|
||||
return; // can't populate if the root is offline
|
||||
}
|
||||
|
||||
final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!");
|
||||
final URL url = requireNonNull(getUrl(), "Missing instance URL!");
|
||||
|
||||
try {
|
||||
// IMPORTANT: the url for repository records does not reliably point to the API url.
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.kohsuke.github;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import static org.kohsuke.github.Previews.BAPTISTE;
|
||||
import static org.kohsuke.github.internal.Previews.BAPTISTE;
|
||||
|
||||
abstract class GHRepositoryBuilder<S> extends AbstractBuilder<GHRepository, S> {
|
||||
|
||||
|
||||
149
src/main/java/org/kohsuke/github/GHWorkflow.java
Normal file
149
src/main/java/org/kohsuke/github/GHWorkflow.java
Normal file
@@ -0,0 +1,149 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A workflow.
|
||||
*
|
||||
* @author Guillaume Smet
|
||||
* @see GHRepository#getWorkflow(long)
|
||||
*/
|
||||
public class GHWorkflow extends GHObject {
|
||||
|
||||
// Not provided by the API.
|
||||
@JsonIgnore
|
||||
private GHRepository owner;
|
||||
|
||||
private String name;
|
||||
private String path;
|
||||
private String state;
|
||||
|
||||
private String htmlUrl;
|
||||
private String badgeUrl;
|
||||
|
||||
/**
|
||||
* The name of the workflow.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The path of the workflow e.g. .github/workflows/blank.yaml
|
||||
*
|
||||
* @return the path
|
||||
*/
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* The state of the workflow.
|
||||
*
|
||||
* @return the state
|
||||
*/
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getHtmlUrl() throws IOException {
|
||||
return GitHubClient.parseURL(htmlUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* The badge URL, like https://github.com/octo-org/octo-repo/workflows/CI/badge.svg
|
||||
*
|
||||
* @return the badge url
|
||||
*/
|
||||
public URL getBadgeUrl() {
|
||||
return GitHubClient.parseURL(badgeUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the workflow.
|
||||
*
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public void disable() throws IOException {
|
||||
root.createRequest().method("PUT").withUrlPath(getApiRoute(), "disable").fetchHttpStatusCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the workflow.
|
||||
*
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public void enable() throws IOException {
|
||||
root.createRequest().method("PUT").withUrlPath(getApiRoute(), "enable").fetchHttpStatusCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a workflow dispatch event which triggers a manual workflow run.
|
||||
*
|
||||
* @param ref
|
||||
* the git reference for the workflow. The reference can be a branch or tag name.
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public void dispatch(String ref) throws IOException {
|
||||
dispatch(ref, Collections.emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a workflow dispatch event which triggers a manual workflow run.
|
||||
*
|
||||
* @param ref
|
||||
* the git reference for the workflow. The reference can be a branch or tag name.
|
||||
* @param inputs
|
||||
* input keys and values configured in the workflow file. The maximum number of properties is 10. Any
|
||||
* default properties configured in the workflow file will be used when inputs are omitted.
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public void dispatch(String ref, Map<String, Object> inputs) throws IOException {
|
||||
Requester requester = root.createRequest()
|
||||
.method("POST")
|
||||
.withUrlPath(getApiRoute(), "dispatches")
|
||||
.with("ref", ref);
|
||||
|
||||
if (!inputs.isEmpty()) {
|
||||
requester.with("inputs", inputs);
|
||||
}
|
||||
|
||||
requester.fetchHttpStatusCode();
|
||||
}
|
||||
|
||||
private String getApiRoute() {
|
||||
if (owner == null) {
|
||||
// Workflow runs returned from search to do not have an owner. Attempt to use url.
|
||||
final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!");
|
||||
return StringUtils.prependIfMissing(url.toString().replace(root.getApiUrl(), ""), "/");
|
||||
|
||||
}
|
||||
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/actions/workflows/" + getId();
|
||||
}
|
||||
|
||||
GHWorkflow wrapUp(GHRepository owner) {
|
||||
this.owner = owner;
|
||||
return wrapUp(owner.root);
|
||||
}
|
||||
|
||||
GHWorkflow wrapUp(GitHub root) {
|
||||
this.root = root;
|
||||
if (owner != null)
|
||||
owner.wrap(root);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
387
src/main/java/org/kohsuke/github/GHWorkflowRun.java
Normal file
387
src/main/java/org/kohsuke/github/GHWorkflowRun.java
Normal file
@@ -0,0 +1,387 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.kohsuke.github.internal.EnumUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A workflow run.
|
||||
*
|
||||
* @author Guillaume Smet
|
||||
* @see GHRepository#getWorkflowRun(long)
|
||||
*/
|
||||
public class GHWorkflowRun extends GHObject {
|
||||
|
||||
@JsonProperty("repository")
|
||||
private GHRepository owner;
|
||||
|
||||
private String name;
|
||||
private long runNumber;
|
||||
private long workflowId;
|
||||
|
||||
private String htmlUrl;
|
||||
private String jobsUrl;
|
||||
private String logsUrl;
|
||||
private String checkSuiteUrl;
|
||||
private String artifactsUrl;
|
||||
private String cancelUrl;
|
||||
private String rerunUrl;
|
||||
private String workflowUrl;
|
||||
|
||||
private String headBranch;
|
||||
private String headSha;
|
||||
private GHRepository headRepository;
|
||||
private HeadCommit headCommit;
|
||||
|
||||
private String event;
|
||||
private String status;
|
||||
private String conclusion;
|
||||
|
||||
private GHPullRequest[] pullRequests;
|
||||
|
||||
/**
|
||||
* The name of the workflow run.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The run number.
|
||||
*
|
||||
* @return the run number
|
||||
*/
|
||||
public long getRunNumber() {
|
||||
return runNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* The workflow id.
|
||||
*
|
||||
* @return the workflow id
|
||||
*/
|
||||
public long getWorkflowId() {
|
||||
return workflowId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getHtmlUrl() throws IOException {
|
||||
return GitHubClient.parseURL(htmlUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* The jobs URL, like https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/jobs
|
||||
*
|
||||
* @return the diff url
|
||||
*/
|
||||
public URL getJobsUrl() {
|
||||
return GitHubClient.parseURL(jobsUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* The logs URL, like https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/logs
|
||||
*
|
||||
* @return the diff url
|
||||
*/
|
||||
public URL getLogsUrl() {
|
||||
return GitHubClient.parseURL(logsUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* The check suite URL, like https://api.github.com/repos/octo-org/octo-repo/check-suites/414944374
|
||||
*
|
||||
* @return the diff url
|
||||
*/
|
||||
public URL getCheckSuiteUrl() {
|
||||
return GitHubClient.parseURL(checkSuiteUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* The artifacts URL, like https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/artifacts
|
||||
*
|
||||
* @return the diff url
|
||||
*/
|
||||
public URL getArtifactsUrl() {
|
||||
return GitHubClient.parseURL(artifactsUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* The cancel URL, like https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/cancel
|
||||
*
|
||||
* @return the diff url
|
||||
*/
|
||||
public URL getCancelUrl() {
|
||||
return GitHubClient.parseURL(cancelUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* The rerun URL, like https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/rerun
|
||||
*
|
||||
* @return the diff url
|
||||
*/
|
||||
public URL getRerunUrl() {
|
||||
return GitHubClient.parseURL(rerunUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* The workflow URL, like https://api.github.com/repos/octo-org/octo-repo/actions/workflows/159038
|
||||
*
|
||||
* @return the diff url
|
||||
*/
|
||||
public URL getWorkflowUrl() {
|
||||
return GitHubClient.parseURL(workflowUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* The head branch name the changes are on.
|
||||
*
|
||||
* @return head branch name
|
||||
*/
|
||||
public String getHeadBranch() {
|
||||
return headBranch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HEAD SHA.
|
||||
*
|
||||
* @return sha for the HEAD commit
|
||||
*/
|
||||
public String getHeadSha() {
|
||||
return headSha;
|
||||
}
|
||||
|
||||
/**
|
||||
* The commit of current head.
|
||||
*
|
||||
* @return head commit
|
||||
*/
|
||||
public HeadCommit getHeadCommit() {
|
||||
return headCommit;
|
||||
}
|
||||
|
||||
/**
|
||||
* The repository of current head.
|
||||
*
|
||||
* @return head repository
|
||||
*/
|
||||
public GHRepository getHeadRepository() {
|
||||
return headRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of event that triggered the build.
|
||||
*
|
||||
* @return type of event
|
||||
*/
|
||||
public GHEvent getEvent() {
|
||||
return Enum.valueOf(GHEvent.class, event.toUpperCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets status of the workflow run.
|
||||
* <p>
|
||||
* Can be {@code UNKNOWN} if the value returned by GitHub is unknown from the API.
|
||||
*
|
||||
* @return status of the workflow run
|
||||
*/
|
||||
public Status getStatus() {
|
||||
return Status.from(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the conclusion of the workflow run.
|
||||
* <p>
|
||||
* Can be {@code UNKNOWN} if the value returned by GitHub is unknown from the API.
|
||||
*
|
||||
* @return conclusion of the workflow run
|
||||
*/
|
||||
public Conclusion getConclusion() {
|
||||
return Conclusion.from(conclusion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pull requests participated in this workflow run.
|
||||
*
|
||||
* Note this field is only populated for events. When getting a {@link GHWorkflowRun} outside of an event, this is
|
||||
* always empty.
|
||||
*
|
||||
* @return the list of {@link GHPullRequest}s for this workflow run. Only populated for events.
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public List<GHPullRequest> getPullRequests() throws IOException {
|
||||
if (pullRequests != null && pullRequests.length != 0) {
|
||||
for (GHPullRequest pullRequest : pullRequests) {
|
||||
// Only refresh if we haven't do so before
|
||||
pullRequest.refresh(pullRequest.getTitle());
|
||||
}
|
||||
return Collections.unmodifiableList(Arrays.asList(pullRequests));
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the workflow run.
|
||||
*
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public void cancel() throws IOException {
|
||||
root.createRequest().method("POST").withUrlPath(getApiRoute(), "cancel").fetchHttpStatusCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the workflow run.
|
||||
*
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public void delete() throws IOException {
|
||||
root.createRequest().method("DELETE").withUrlPath(getApiRoute()).fetchHttpStatusCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rerun the workflow run.
|
||||
*
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public void rerun() throws IOException {
|
||||
root.createRequest().method("POST").withUrlPath(getApiRoute(), "rerun").fetchHttpStatusCode();
|
||||
}
|
||||
|
||||
private String getApiRoute() {
|
||||
if (owner == null) {
|
||||
// Workflow runs returned from search to do not have an owner. Attempt to use url.
|
||||
final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!");
|
||||
return StringUtils.prependIfMissing(url.toString().replace(root.getApiUrl(), ""), "/");
|
||||
|
||||
}
|
||||
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/actions/runs/" + getId();
|
||||
}
|
||||
|
||||
GHWorkflowRun wrapUp(GHRepository owner) {
|
||||
this.owner = owner;
|
||||
return wrapUp(owner.root);
|
||||
}
|
||||
|
||||
GHWorkflowRun wrapUp(GitHub root) {
|
||||
this.root = root;
|
||||
if (owner != null) {
|
||||
owner.wrap(root);
|
||||
if (pullRequests != null) {
|
||||
for (GHPullRequest singlePull : pullRequests) {
|
||||
singlePull.wrap(owner);
|
||||
}
|
||||
}
|
||||
} else if (pullRequests != null) {
|
||||
for (GHPullRequest singlePull : pullRequests) {
|
||||
singlePull.wrap(root);
|
||||
}
|
||||
}
|
||||
if (headRepository != null) {
|
||||
headRepository.wrap(root);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class HeadCommit {
|
||||
private String id;
|
||||
private String treeId;
|
||||
private String message;
|
||||
private String timestamp;
|
||||
private GitUser author;
|
||||
private GitUser committer;
|
||||
|
||||
/**
|
||||
* Gets id of the commit
|
||||
*
|
||||
* @return id of the commit
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets id of the tree.
|
||||
*
|
||||
* @return id of the tree
|
||||
*/
|
||||
public String getTreeId() {
|
||||
return treeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets message.
|
||||
*
|
||||
* @return commit message.
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets timestamp of the commit.
|
||||
*
|
||||
* @return timestamp of the commit
|
||||
*/
|
||||
public Date getTimestamp() {
|
||||
return GitHubClient.parseDate(timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets author.
|
||||
*
|
||||
* @return the author
|
||||
*/
|
||||
public GitUser getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets committer.
|
||||
*
|
||||
* @return the committer
|
||||
*/
|
||||
public GitUser getCommitter() {
|
||||
return committer;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Status {
|
||||
QUEUED, IN_PROGRESS, COMPLETED, UNKNOWN;
|
||||
|
||||
public static Status from(String value) {
|
||||
return EnumUtils.getNullableEnumOrDefault(Status.class, value, Status.UNKNOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Conclusion {
|
||||
ACTION_REQUIRED, CANCELLED, FAILURE, NEUTRAL, SUCCESS, SKIPPED, STALE, TIMED_OUT, UNKNOWN;
|
||||
|
||||
public static Conclusion from(String value) {
|
||||
return EnumUtils.getNullableEnumOrDefault(Conclusion.class, value, Conclusion.UNKNOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
}
|
||||
101
src/main/java/org/kohsuke/github/GHWorkflowRunQueryBuilder.java
Normal file
101
src/main/java/org/kohsuke/github/GHWorkflowRunQueryBuilder.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.kohsuke.github.GHWorkflowRun.Status;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
/**
|
||||
* Lists up workflow runs with some filtering and sorting.
|
||||
*
|
||||
* @author Guillaume Smet
|
||||
* @see GHRepository#queryWorkflowRuns()
|
||||
*/
|
||||
public class GHWorkflowRunQueryBuilder extends GHQueryBuilder<GHWorkflowRun> {
|
||||
private final GHRepository repo;
|
||||
|
||||
GHWorkflowRunQueryBuilder(GHRepository repo) {
|
||||
super(repo.root);
|
||||
this.repo = repo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actor workflow run query builder.
|
||||
*
|
||||
* @param actor
|
||||
* the actor
|
||||
* @return the gh workflow run query builder
|
||||
*/
|
||||
public GHWorkflowRunQueryBuilder actor(String actor) {
|
||||
req.with("actor", actor);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actor workflow run query builder.
|
||||
*
|
||||
* @param actor
|
||||
* the actor
|
||||
* @return the gh workflow run query builder
|
||||
*/
|
||||
public GHWorkflowRunQueryBuilder actor(GHUser actor) {
|
||||
req.with("actor", actor.getLogin());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Branch workflow run query builder.
|
||||
*
|
||||
* @param branch
|
||||
* the branch
|
||||
* @return the gh workflow run query builder
|
||||
*/
|
||||
public GHWorkflowRunQueryBuilder branch(String branch) {
|
||||
req.with("branch", branch);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event workflow run query builder.
|
||||
*
|
||||
* @param event
|
||||
* the event
|
||||
* @return the gh workflow run query builder
|
||||
*/
|
||||
public GHWorkflowRunQueryBuilder event(GHEvent event) {
|
||||
req.with("event", event.symbol());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event workflow run query builder.
|
||||
*
|
||||
* @param event
|
||||
* the event
|
||||
* @return the gh workflow run query builder
|
||||
*/
|
||||
public GHWorkflowRunQueryBuilder event(String event) {
|
||||
req.with("event", event);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Status workflow run query builder.
|
||||
*
|
||||
* @param status
|
||||
* the status
|
||||
* @return the gh workflow run query builder
|
||||
*/
|
||||
public GHWorkflowRunQueryBuilder status(Status status) {
|
||||
req.with("status", status.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PagedIterable<GHWorkflowRun> list() {
|
||||
try {
|
||||
return new GHWorkflowRunsIterable(root, req.withUrlPath(repo.getApiTailUrl("actions/runs")).build());
|
||||
} catch (MalformedURLException e) {
|
||||
throw new GHException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
44
src/main/java/org/kohsuke/github/GHWorkflowRunsIterable.java
Normal file
44
src/main/java/org/kohsuke/github/GHWorkflowRunsIterable.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Iterable for workflow runs listing.
|
||||
*/
|
||||
class GHWorkflowRunsIterable extends PagedIterable<GHWorkflowRun> {
|
||||
private final transient GitHub root;
|
||||
private final GitHubRequest request;
|
||||
|
||||
private GHWorkflowRunsPage result;
|
||||
|
||||
public GHWorkflowRunsIterable(GitHub root, GitHubRequest request) {
|
||||
this.root = root;
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PagedIterator<GHWorkflowRun> _iterator(int pageSize) {
|
||||
return new PagedIterator<>(
|
||||
adapt(GitHubPageIterator.create(root.getClient(), GHWorkflowRunsPage.class, request, pageSize)),
|
||||
null);
|
||||
}
|
||||
|
||||
protected Iterator<GHWorkflowRun[]> adapt(final Iterator<GHWorkflowRunsPage> base) {
|
||||
return new Iterator<GHWorkflowRun[]>() {
|
||||
public boolean hasNext() {
|
||||
return base.hasNext();
|
||||
}
|
||||
|
||||
public GHWorkflowRun[] next() {
|
||||
GHWorkflowRunsPage v = base.next();
|
||||
if (result == null) {
|
||||
result = v;
|
||||
}
|
||||
return v.getWorkflowRuns(root);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
20
src/main/java/org/kohsuke/github/GHWorkflowRunsPage.java
Normal file
20
src/main/java/org/kohsuke/github/GHWorkflowRunsPage.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
/**
|
||||
* Represents the one page of workflow runs result when listing workflow runs.
|
||||
*/
|
||||
class GHWorkflowRunsPage {
|
||||
private int totalCount;
|
||||
private GHWorkflowRun[] workflowRuns;
|
||||
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
GHWorkflowRun[] getWorkflowRuns(GitHub root) {
|
||||
for (GHWorkflowRun workflowRun : workflowRuns) {
|
||||
workflowRun.wrapUp(root);
|
||||
}
|
||||
return workflowRuns;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,8 @@ package org.kohsuke.github;
|
||||
import com.fasterxml.jackson.databind.ObjectReader;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||
import org.kohsuke.github.authorization.AuthorizationProvider;
|
||||
import org.kohsuke.github.internal.Previews;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
@@ -37,8 +39,8 @@ import java.util.logging.Logger;
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static org.kohsuke.github.Previews.INERTIA;
|
||||
import static org.kohsuke.github.Previews.MACHINE_MAN;
|
||||
import static org.kohsuke.github.internal.Previews.INERTIA;
|
||||
import static org.kohsuke.github.internal.Previews.MACHINE_MAN;
|
||||
|
||||
/**
|
||||
* Root of the GitHub API.
|
||||
@@ -93,39 +95,112 @@ public class GitHub {
|
||||
* "http://ghe.acme.com/api/v3". Note that GitHub Enterprise has <code>/api/v3</code> in the URL. For
|
||||
* historical reasons, this parameter still accepts the bare domain name, but that's considered
|
||||
* deprecated. Password is also considered deprecated as it is no longer required for api usage.
|
||||
* @param login
|
||||
* The user ID on GitHub that you are logging in as. Can be omitted if the OAuth token is provided or if
|
||||
* logging in anonymously. Specifying this would save one API call.
|
||||
* @param oauthAccessToken
|
||||
* Secret OAuth token.
|
||||
* @param password
|
||||
* User's password. Always used in conjunction with the {@code login} parameter
|
||||
* @param connector
|
||||
* HttpConnector to use. Pass null to use default connector.
|
||||
* a connector
|
||||
* @param rateLimitHandler
|
||||
* rateLimitHandler
|
||||
* @param abuseLimitHandler
|
||||
* abuseLimitHandler
|
||||
* @param rateLimitChecker
|
||||
* rateLimitChecker
|
||||
* @param authorizationProvider
|
||||
* a authorization provider
|
||||
*/
|
||||
GitHub(String apiUrl,
|
||||
String login,
|
||||
String oauthAccessToken,
|
||||
String jwtToken,
|
||||
String password,
|
||||
HttpConnector connector,
|
||||
RateLimitHandler rateLimitHandler,
|
||||
AbuseLimitHandler abuseLimitHandler,
|
||||
GitHubRateLimitChecker rateLimitChecker) throws IOException {
|
||||
GitHubRateLimitChecker rateLimitChecker,
|
||||
AuthorizationProvider authorizationProvider) throws IOException {
|
||||
if (authorizationProvider instanceof DependentAuthorizationProvider) {
|
||||
((DependentAuthorizationProvider) authorizationProvider).bind(this);
|
||||
}
|
||||
|
||||
this.client = new GitHubHttpUrlConnectionClient(apiUrl,
|
||||
login,
|
||||
oauthAccessToken,
|
||||
jwtToken,
|
||||
password,
|
||||
connector,
|
||||
rateLimitHandler,
|
||||
abuseLimitHandler,
|
||||
rateLimitChecker,
|
||||
(myself) -> setMyself(myself));
|
||||
(myself) -> setMyself(myself),
|
||||
authorizationProvider);
|
||||
users = new ConcurrentHashMap<>();
|
||||
orgs = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
private GitHub(GitHubClient client) {
|
||||
this.client = client;
|
||||
users = new ConcurrentHashMap<>();
|
||||
orgs = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public static abstract class DependentAuthorizationProvider implements AuthorizationProvider {
|
||||
|
||||
private GitHub baseGitHub;
|
||||
private GitHub gitHub;
|
||||
private final AuthorizationProvider authorizationProvider;
|
||||
|
||||
/**
|
||||
* An AuthorizationProvider that requires an authenticated GitHub instance to provide its authorization.
|
||||
*
|
||||
* @param authorizationProvider
|
||||
* A authorization provider to be used when refreshing this authorization provider.
|
||||
*/
|
||||
@BetaApi
|
||||
@Deprecated
|
||||
protected DependentAuthorizationProvider(AuthorizationProvider authorizationProvider) {
|
||||
this.authorizationProvider = authorizationProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds this authorization provider to a github instance.
|
||||
*
|
||||
* Only needs to be implemented by dynamic credentials providers that use a github instance in order to refresh.
|
||||
*
|
||||
* @param github
|
||||
* The github instance to be used for refreshing dynamic credentials
|
||||
*/
|
||||
synchronized void bind(GitHub github) {
|
||||
if (baseGitHub != null) {
|
||||
throw new IllegalStateException("Already bound to another GitHub instance.");
|
||||
}
|
||||
this.baseGitHub = github;
|
||||
}
|
||||
|
||||
protected synchronized final GitHub gitHub() {
|
||||
if (gitHub == null) {
|
||||
gitHub = new GitHub.AuthorizationRefreshGitHubWrapper(this.baseGitHub, authorizationProvider);
|
||||
}
|
||||
return gitHub;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AuthorizationRefreshGitHubWrapper extends GitHub {
|
||||
|
||||
private final AuthorizationProvider authorizationProvider;
|
||||
|
||||
AuthorizationRefreshGitHubWrapper(GitHub github, AuthorizationProvider authorizationProvider) {
|
||||
super(github.client);
|
||||
this.authorizationProvider = authorizationProvider;
|
||||
|
||||
// no dependent authorization providers nest like this currently, but they might in future
|
||||
if (authorizationProvider instanceof DependentAuthorizationProvider) {
|
||||
((DependentAuthorizationProvider) authorizationProvider).bind(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
Requester createRequest() {
|
||||
try {
|
||||
// Override
|
||||
return super.createRequest().setHeader("Authorization", authorizationProvider.getEncodedAuthorization())
|
||||
.rateLimit(RateLimitTarget.NONE);
|
||||
} catch (IOException e) {
|
||||
throw new GHException("Failed to create requester to refresh credentials", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the credential from "~/.github" or from the System Environment Properties.
|
||||
*
|
||||
@@ -557,11 +632,28 @@ public class GitHub {
|
||||
* @return the repository by id
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*
|
||||
* @deprecated Do not use this method. It was added due to misunderstanding of the type of parameter. Use
|
||||
* {@link #getRepositoryById(long)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public GHRepository getRepositoryById(String id) throws IOException {
|
||||
return createRequest().withUrlPath("/repositories/" + id).fetch(GHRepository.class).wrap(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the repository object from its ID
|
||||
*
|
||||
* @param id
|
||||
* the id
|
||||
* @return the repository by id
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public GHRepository getRepositoryById(long id) throws IOException {
|
||||
return createRequest().withUrlPath("/repositories/" + id).fetch(GHRepository.class).wrap(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of popular open source licenses
|
||||
*
|
||||
@@ -1203,7 +1295,7 @@ public class GitHub {
|
||||
.with(new ByteArrayInputStream(text.getBytes("UTF-8")))
|
||||
.contentType("text/plain;charset=UTF-8")
|
||||
.withUrlPath("/markdown/raw")
|
||||
.fetchStream(),
|
||||
.fetchStream(Requester::copyInputStream),
|
||||
"UTF-8");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.kohsuke.github.authorization.AuthorizationProvider;
|
||||
import org.kohsuke.github.authorization.ImmutableAuthorizationProvider;
|
||||
import org.kohsuke.github.extras.ImpatientHttpConnector;
|
||||
|
||||
import java.io.File;
|
||||
@@ -24,16 +26,13 @@ public class GitHubBuilder implements Cloneable {
|
||||
|
||||
// default scoped so unit tests can read them.
|
||||
/* private */ String endpoint = GitHubClient.GITHUB_URL;
|
||||
/* private */ String user;
|
||||
/* private */ String password;
|
||||
/* private */ String oauthToken;
|
||||
/* private */ String jwtToken;
|
||||
|
||||
private HttpConnector connector;
|
||||
|
||||
private RateLimitHandler rateLimitHandler = RateLimitHandler.WAIT;
|
||||
private AbuseLimitHandler abuseLimitHandler = AbuseLimitHandler.WAIT;
|
||||
private GitHubRateLimitChecker rateLimitChecker = new GitHubRateLimitChecker();
|
||||
/* private */ AuthorizationProvider authorizationProvider = AuthorizationProvider.ANONYMOUS;
|
||||
|
||||
/**
|
||||
* Instantiates a new Git hub builder.
|
||||
@@ -61,13 +60,13 @@ public class GitHubBuilder implements Cloneable {
|
||||
|
||||
builder = fromEnvironment();
|
||||
|
||||
if (builder.oauthToken != null || builder.user != null || builder.jwtToken != null)
|
||||
if (builder.authorizationProvider != null)
|
||||
return builder;
|
||||
|
||||
try {
|
||||
builder = fromPropertyFile();
|
||||
|
||||
if (builder.oauthToken != null || builder.user != null || builder.jwtToken != null)
|
||||
if (builder.authorizationProvider != null)
|
||||
return builder;
|
||||
} catch (FileNotFoundException e) {
|
||||
// fall through
|
||||
@@ -215,9 +214,20 @@ public class GitHubBuilder implements Cloneable {
|
||||
*/
|
||||
public static GitHubBuilder fromProperties(Properties props) {
|
||||
GitHubBuilder self = new GitHubBuilder();
|
||||
self.withOAuthToken(props.getProperty("oauth"), props.getProperty("login"));
|
||||
self.withJwtToken(props.getProperty("jwt"));
|
||||
self.withPassword(props.getProperty("login"), props.getProperty("password"));
|
||||
String oauth = props.getProperty("oauth");
|
||||
String jwt = props.getProperty("jwt");
|
||||
String login = props.getProperty("login");
|
||||
String password = props.getProperty("password");
|
||||
|
||||
if (oauth != null) {
|
||||
self.withOAuthToken(oauth, login);
|
||||
}
|
||||
if (jwt != null) {
|
||||
self.withJwtToken(jwt);
|
||||
}
|
||||
if (password != null) {
|
||||
self.withPassword(login, password);
|
||||
}
|
||||
self.withEndpoint(props.getProperty("endpoint", GitHubClient.GITHUB_URL));
|
||||
return self;
|
||||
}
|
||||
@@ -247,9 +257,7 @@ public class GitHubBuilder implements Cloneable {
|
||||
* @return the git hub builder
|
||||
*/
|
||||
public GitHubBuilder withPassword(String user, String password) {
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
return this;
|
||||
return withAuthorizationProvider(ImmutableAuthorizationProvider.fromLoginAndPassword(user, password));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,7 +268,7 @@ public class GitHubBuilder implements Cloneable {
|
||||
* @return the git hub builder
|
||||
*/
|
||||
public GitHubBuilder withOAuthToken(String oauthToken) {
|
||||
return withOAuthToken(oauthToken, null);
|
||||
return withAuthorizationProvider(ImmutableAuthorizationProvider.fromOauthToken(oauthToken));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,8 +281,21 @@ public class GitHubBuilder implements Cloneable {
|
||||
* @return the git hub builder
|
||||
*/
|
||||
public GitHubBuilder withOAuthToken(String oauthToken, String user) {
|
||||
this.oauthToken = oauthToken;
|
||||
this.user = user;
|
||||
return withAuthorizationProvider(ImmutableAuthorizationProvider.fromOauthToken(oauthToken, user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a {@link AuthorizationProvider} for this builder
|
||||
*
|
||||
* There can be only one authorization provider per client instance.
|
||||
*
|
||||
* @param authorizationProvider
|
||||
* the authorization provider
|
||||
* @return the git hub builder
|
||||
*
|
||||
*/
|
||||
public GitHubBuilder withAuthorizationProvider(final AuthorizationProvider authorizationProvider) {
|
||||
this.authorizationProvider = authorizationProvider;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -287,7 +308,7 @@ public class GitHubBuilder implements Cloneable {
|
||||
* @see GHAppInstallation#createToken(java.util.Map) GHAppInstallation#createToken(java.util.Map)
|
||||
*/
|
||||
public GitHubBuilder withAppInstallationToken(String appInstallationToken) {
|
||||
return withOAuthToken(appInstallationToken, "");
|
||||
return withAuthorizationProvider(ImmutableAuthorizationProvider.fromAppInstallationToken(appInstallationToken));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -298,8 +319,7 @@ public class GitHubBuilder implements Cloneable {
|
||||
* @return the git hub builder
|
||||
*/
|
||||
public GitHubBuilder withJwtToken(String jwtToken) {
|
||||
this.jwtToken = jwtToken;
|
||||
return this;
|
||||
return withAuthorizationProvider(ImmutableAuthorizationProvider.fromJwtToken(jwtToken));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -421,14 +441,11 @@ public class GitHubBuilder implements Cloneable {
|
||||
*/
|
||||
public GitHub build() throws IOException {
|
||||
return new GitHub(endpoint,
|
||||
user,
|
||||
oauthToken,
|
||||
jwtToken,
|
||||
password,
|
||||
connector,
|
||||
rateLimitHandler,
|
||||
abuseLimitHandler,
|
||||
rateLimitChecker);
|
||||
rateLimitChecker,
|
||||
authorizationProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,33 +1,19 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.InjectableValues;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectReader;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.introspect.VisibilityChecker;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.kohsuke.github.authorization.AuthorizationProvider;
|
||||
import org.kohsuke.github.authorization.UserAuthorizationProvider;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.net.*;
|
||||
import java.time.Instant;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -56,17 +42,13 @@ abstract class GitHubClient {
|
||||
static final int retryTimeoutMillis = 100;
|
||||
/* private */ final String login;
|
||||
|
||||
/**
|
||||
* Value of the authorization header to be sent with the request.
|
||||
*/
|
||||
/* private */ final String encodedAuthorization;
|
||||
|
||||
// Cache of myself object.
|
||||
private final String apiUrl;
|
||||
|
||||
protected final RateLimitHandler rateLimitHandler;
|
||||
protected final AbuseLimitHandler abuseLimitHandler;
|
||||
private final GitHubRateLimitChecker rateLimitChecker;
|
||||
private final AuthorizationProvider authorizationProvider;
|
||||
|
||||
private HttpConnector connector;
|
||||
|
||||
@@ -91,15 +73,12 @@ abstract class GitHubClient {
|
||||
}
|
||||
|
||||
GitHubClient(String apiUrl,
|
||||
String login,
|
||||
String oauthAccessToken,
|
||||
String jwtToken,
|
||||
String password,
|
||||
HttpConnector connector,
|
||||
RateLimitHandler rateLimitHandler,
|
||||
AbuseLimitHandler abuseLimitHandler,
|
||||
GitHubRateLimitChecker rateLimitChecker,
|
||||
Consumer<GHMyself> myselfConsumer) throws IOException {
|
||||
Consumer<GHMyself> myselfConsumer,
|
||||
AuthorizationProvider authorizationProvider) throws IOException {
|
||||
|
||||
if (apiUrl.endsWith("/")) {
|
||||
apiUrl = apiUrl.substring(0, apiUrl.length() - 1); // normalize
|
||||
@@ -111,33 +90,38 @@ abstract class GitHubClient {
|
||||
this.apiUrl = apiUrl;
|
||||
this.connector = connector;
|
||||
|
||||
if (oauthAccessToken != null) {
|
||||
encodedAuthorization = "token " + oauthAccessToken;
|
||||
} else {
|
||||
if (jwtToken != null) {
|
||||
encodedAuthorization = "Bearer " + jwtToken;
|
||||
} else if (password != null) {
|
||||
String authorization = (login + ':' + password);
|
||||
String charsetName = StandardCharsets.UTF_8.name();
|
||||
encodedAuthorization = "Basic "
|
||||
+ Base64.getEncoder().encodeToString(authorization.getBytes(charsetName));
|
||||
} else {// anonymous access
|
||||
encodedAuthorization = null;
|
||||
}
|
||||
}
|
||||
// Prefer credential configuration via provider
|
||||
this.authorizationProvider = authorizationProvider;
|
||||
|
||||
this.rateLimitHandler = rateLimitHandler;
|
||||
this.abuseLimitHandler = abuseLimitHandler;
|
||||
this.rateLimitChecker = rateLimitChecker;
|
||||
|
||||
if (login == null && encodedAuthorization != null && jwtToken == null) {
|
||||
GHMyself myself = fetch(GHMyself.class, "/user");
|
||||
login = myself.getLogin();
|
||||
if (myselfConsumer != null) {
|
||||
myselfConsumer.accept(myself);
|
||||
this.login = getCurrentUser(myselfConsumer);
|
||||
}
|
||||
|
||||
private String getCurrentUser(Consumer<GHMyself> myselfConsumer) throws IOException {
|
||||
String login = null;
|
||||
if (this.authorizationProvider instanceof UserAuthorizationProvider
|
||||
&& this.authorizationProvider.getEncodedAuthorization() != null) {
|
||||
|
||||
UserAuthorizationProvider userAuthorizationProvider = (UserAuthorizationProvider) this.authorizationProvider;
|
||||
|
||||
login = userAuthorizationProvider.getLogin();
|
||||
|
||||
if (login == null) {
|
||||
try {
|
||||
GHMyself myself = fetch(GHMyself.class, "/user");
|
||||
if (myselfConsumer != null) {
|
||||
myselfConsumer.accept(myself);
|
||||
}
|
||||
login = myself.getLogin();
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.login = login;
|
||||
return login;
|
||||
}
|
||||
|
||||
private <T> T fetch(Class<T> type, String urlPath) throws IOException {
|
||||
@@ -202,7 +186,13 @@ abstract class GitHubClient {
|
||||
* @return {@code true} if operations that require authentication will fail.
|
||||
*/
|
||||
public boolean isAnonymous() {
|
||||
return login == null && encodedAuthorization == null;
|
||||
try {
|
||||
return login == null && this.authorizationProvider.getEncodedAuthorization() == null;
|
||||
} catch (IOException e) {
|
||||
// An exception here means that the provider failed to provide authorization parameters,
|
||||
// basically meaning the same as "no auth"
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,6 +214,11 @@ abstract class GitHubClient {
|
||||
return getRateLimit(RateLimitTarget.NONE);
|
||||
}
|
||||
|
||||
@CheckForNull
|
||||
protected String getEncodedAuthorization() throws IOException {
|
||||
return authorizationProvider.getEncodedAuthorization();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
GHRateLimit getRateLimit(@Nonnull RateLimitTarget rateLimitTarget) throws IOException {
|
||||
GHRateLimit result;
|
||||
@@ -394,7 +389,6 @@ abstract class GitHubClient {
|
||||
"GitHub API request [" + (login == null ? "anonymous" : login) + "]: "
|
||||
+ request.method() + " " + request.url().toString());
|
||||
}
|
||||
|
||||
rateLimitChecker.checkRateLimit(this, request);
|
||||
|
||||
responseInfo = getResponseInfo(request);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.kohsuke.github.authorization.AuthorizationProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -33,25 +34,19 @@ import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
class GitHubHttpUrlConnectionClient extends GitHubClient {
|
||||
|
||||
GitHubHttpUrlConnectionClient(String apiUrl,
|
||||
String login,
|
||||
String oauthAccessToken,
|
||||
String jwtToken,
|
||||
String password,
|
||||
HttpConnector connector,
|
||||
RateLimitHandler rateLimitHandler,
|
||||
AbuseLimitHandler abuseLimitHandler,
|
||||
GitHubRateLimitChecker rateLimitChecker,
|
||||
Consumer<GHMyself> myselfConsumer) throws IOException {
|
||||
Consumer<GHMyself> myselfConsumer,
|
||||
AuthorizationProvider authorizationProvider) throws IOException {
|
||||
super(apiUrl,
|
||||
login,
|
||||
oauthAccessToken,
|
||||
jwtToken,
|
||||
password,
|
||||
connector,
|
||||
rateLimitHandler,
|
||||
abuseLimitHandler,
|
||||
rateLimitChecker,
|
||||
myselfConsumer);
|
||||
myselfConsumer,
|
||||
authorizationProvider);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -114,8 +109,12 @@ class GitHubHttpUrlConnectionClient extends GitHubClient {
|
||||
|
||||
// if the authentication is needed but no credential is given, try it anyway (so that some calls
|
||||
// that do work with anonymous access in the reduced form should still work.)
|
||||
if (client.encodedAuthorization != null)
|
||||
connection.setRequestProperty("Authorization", client.encodedAuthorization);
|
||||
if (!request.headers().containsKey("Authorization")) {
|
||||
String authorization = client.getEncodedAuthorization();
|
||||
if (authorization != null) {
|
||||
connection.setRequestProperty("Authorization", client.getEncodedAuthorization());
|
||||
}
|
||||
}
|
||||
|
||||
setRequestMethod(request.method(), connection);
|
||||
buildRequest(request, connection);
|
||||
|
||||
@@ -20,4 +20,8 @@ abstract class GitHubInteractiveObject {
|
||||
GitHubInteractiveObject(GitHub root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
GitHub getRoot() {
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.kohsuke.github;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.kohsuke.github.internal.Previews;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.InjectableValues;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.kohsuke.github.function.FunctionThrows;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
@@ -194,24 +195,11 @@ class GitHubResponse<T> {
|
||||
/**
|
||||
* Represents a supplier of results that can throw.
|
||||
*
|
||||
* <p>
|
||||
* This is a <a href="package-summary.html">functional interface</a> whose functional method is
|
||||
* {@link #apply(ResponseInfo)}.
|
||||
*
|
||||
* @param <T>
|
||||
* the type of results supplied by this supplier
|
||||
*/
|
||||
@FunctionalInterface
|
||||
interface BodyHandler<T> {
|
||||
|
||||
/**
|
||||
* Gets a result.
|
||||
*
|
||||
* @return a result
|
||||
* @throws IOException
|
||||
* if an I/O Exception occurs.
|
||||
*/
|
||||
T apply(ResponseInfo input) throws IOException;
|
||||
interface BodyHandler<T> extends FunctionThrows<ResponseInfo, T, IOException> {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.kohsuke.github.internal.Previews;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.kohsuke.github;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.kohsuke.github.Previews.SQUIRREL_GIRL;
|
||||
import static org.kohsuke.github.internal.Previews.SQUIRREL_GIRL;
|
||||
|
||||
/**
|
||||
* Those {@link GHObject}s that can have {@linkplain GHReaction reactions}.
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
*/
|
||||
package org.kohsuke.github;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.kohsuke.github.function.InputStreamFunction;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -106,15 +108,31 @@ class Requester extends GitHubRequest.Builder<Requester> {
|
||||
* Response input stream. There are scenarios where direct stream reading is needed, however it is better to use
|
||||
* {@link #fetch(Class)} where possible.
|
||||
*
|
||||
* @return the input stream
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public InputStream fetchStream() throws IOException {
|
||||
return client
|
||||
.sendRequest(this,
|
||||
(responseInfo) -> new ByteArrayInputStream(IOUtils.toByteArray(responseInfo.bodyStream())))
|
||||
.body();
|
||||
public <T> T fetchStream(@Nonnull InputStreamFunction<T> handler) throws IOException {
|
||||
return client.sendRequest(this, (responseInfo) -> handler.apply(responseInfo.bodyStream())).body();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to make it easy to pull streams.
|
||||
*
|
||||
* Copies an input stream to an in-memory input stream. The performance on this is not great but
|
||||
* {@link GitHubResponse.ResponseInfo#bodyStream()} is closed at the end of every call to
|
||||
* {@link GitHubClient#sendRequest(GitHubRequest, GitHubResponse.BodyHandler)}, so any reads to the original input
|
||||
* stream must be completed before then. There are a number of deprecated methods that return {@link InputStream}.
|
||||
* This method keeps all of them using the same code path.
|
||||
*
|
||||
* @param inputStream
|
||||
* the input stream to be copied
|
||||
* @return an in-memory copy of the passed input stream
|
||||
* @throws IOException
|
||||
* if an error occurs while copying the stream
|
||||
*/
|
||||
@NonNull
|
||||
public static InputStream copyInputStream(InputStream inputStream) throws IOException {
|
||||
return new ByteArrayInputStream(IOUtils.toByteArray(inputStream));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.kohsuke.github.authorization;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Provides a functional interface that returns a valid encodedAuthorization. This strategy allows for a provider that
|
||||
* dynamically changes the credentials. Each request will request the credentials from the provider.
|
||||
*/
|
||||
public interface AuthorizationProvider {
|
||||
/**
|
||||
* An static instance for an ANONYMOUS authorization provider
|
||||
*/
|
||||
AuthorizationProvider ANONYMOUS = new AnonymousAuthorizationProvider();
|
||||
|
||||
/**
|
||||
* Returns the credentials to be used with a given request. As an example, a authorization provider for a bearer
|
||||
* token will return something like:
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
* @Override
|
||||
* public String getEncodedAuthorization() {
|
||||
* return "Bearer myBearerToken";
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @return encoded authorization string, can be null
|
||||
* @throws IOException
|
||||
* on any error that prevents the provider from getting a valid authorization
|
||||
*/
|
||||
String getEncodedAuthorization() throws IOException;
|
||||
|
||||
/**
|
||||
* A {@link AuthorizationProvider} that ensures that no credentials are returned
|
||||
*/
|
||||
class AnonymousAuthorizationProvider implements AuthorizationProvider {
|
||||
@Override
|
||||
public String getEncodedAuthorization() throws IOException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package org.kohsuke.github.authorization;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
|
||||
/**
|
||||
* A {@link AuthorizationProvider} that always returns the same credentials
|
||||
*/
|
||||
public class ImmutableAuthorizationProvider implements AuthorizationProvider {
|
||||
|
||||
private final String authorization;
|
||||
|
||||
public ImmutableAuthorizationProvider(String authorization) {
|
||||
this.authorization = authorization;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and returns a {@link AuthorizationProvider} from a given oauthAccessToken
|
||||
*
|
||||
* @param oauthAccessToken
|
||||
* The token
|
||||
* @return a correctly configured {@link AuthorizationProvider} that will always return the same provided
|
||||
* oauthAccessToken
|
||||
*/
|
||||
public static AuthorizationProvider fromOauthToken(String oauthAccessToken) {
|
||||
return new UserProvider(String.format("token %s", oauthAccessToken));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and returns a {@link AuthorizationProvider} from a given oauthAccessToken
|
||||
*
|
||||
* @param oauthAccessToken
|
||||
* The token
|
||||
* @param login
|
||||
* The login for this token
|
||||
*
|
||||
* @return a correctly configured {@link AuthorizationProvider} that will always return the same provided
|
||||
* oauthAccessToken
|
||||
*/
|
||||
public static AuthorizationProvider fromOauthToken(String oauthAccessToken, String login) {
|
||||
return new UserProvider(String.format("token %s", oauthAccessToken), login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and returns a {@link AuthorizationProvider} from a given App Installation Token
|
||||
*
|
||||
* @param appInstallationToken
|
||||
* A string containing the GitHub App installation token
|
||||
* @return the configured Builder from given GitHub App installation token.
|
||||
*/
|
||||
public static AuthorizationProvider fromAppInstallationToken(String appInstallationToken) {
|
||||
return fromOauthToken(appInstallationToken, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and returns a {@link AuthorizationProvider} from a given jwtToken
|
||||
*
|
||||
* @param jwtToken
|
||||
* The JWT token
|
||||
* @return a correctly configured {@link AuthorizationProvider} that will always return the same provided jwtToken
|
||||
*/
|
||||
public static AuthorizationProvider fromJwtToken(String jwtToken) {
|
||||
return new ImmutableAuthorizationProvider(String.format("Bearer %s", jwtToken));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and returns a {@link AuthorizationProvider} from the given user/password pair
|
||||
*
|
||||
* @param login
|
||||
* The login for the user, usually the same as the username
|
||||
* @param password
|
||||
* The password for the associated user
|
||||
* @return a correctly configured {@link AuthorizationProvider} that will always return the credentials for the same
|
||||
* user and password combo
|
||||
* @deprecated Login with password credentials are no longer supported by GitHub
|
||||
*/
|
||||
@Deprecated
|
||||
public static AuthorizationProvider fromLoginAndPassword(String login, String password) {
|
||||
try {
|
||||
String authorization = (String.format("%s:%s", login, password));
|
||||
String charsetName = StandardCharsets.UTF_8.name();
|
||||
String b64encoded = Base64.getEncoder().encodeToString(authorization.getBytes(charsetName));
|
||||
String encodedAuthorization = String.format("Basic %s", b64encoded);
|
||||
return new UserProvider(encodedAuthorization, login);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// If UTF-8 isn't supported, there are bigger problems
|
||||
throw new IllegalStateException("Could not generate encoded authorization", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEncodedAuthorization() {
|
||||
return this.authorization;
|
||||
}
|
||||
|
||||
/**
|
||||
* An internal class representing all user-related credentials, which are credentials that have a login or should
|
||||
* query the user endpoint for the login matching this credential.
|
||||
*/
|
||||
private static class UserProvider extends ImmutableAuthorizationProvider implements UserAuthorizationProvider {
|
||||
|
||||
private final String login;
|
||||
|
||||
UserProvider(String authorization) {
|
||||
this(authorization, null);
|
||||
}
|
||||
|
||||
UserProvider(String authorization, String login) {
|
||||
super(authorization);
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
@CheckForNull
|
||||
@Override
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.kohsuke.github.authorization;
|
||||
|
||||
import org.kohsuke.github.BetaApi;
|
||||
import org.kohsuke.github.GHAppInstallation;
|
||||
import org.kohsuke.github.GHAppInstallationToken;
|
||||
import org.kohsuke.github.GitHub;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Provides an AuthorizationProvider that performs automatic token refresh.
|
||||
*/
|
||||
public class OrgAppInstallationAuthorizationProvider extends GitHub.DependentAuthorizationProvider {
|
||||
|
||||
private final String organizationName;
|
||||
|
||||
private String latestToken;
|
||||
|
||||
@Nonnull
|
||||
private Instant validUntil = Instant.MIN;
|
||||
|
||||
/**
|
||||
* Provides an AuthorizationProvider that performs automatic token refresh, based on an previously authenticated
|
||||
* github client.
|
||||
*
|
||||
* @param organizationName
|
||||
* The name of the organization where the application is installed
|
||||
* @param authorizationProvider
|
||||
* A authorization provider that returns a JWT token that can be used to refresh the App Installation
|
||||
* token from GitHub.
|
||||
*/
|
||||
@BetaApi
|
||||
@Deprecated
|
||||
public OrgAppInstallationAuthorizationProvider(String organizationName,
|
||||
AuthorizationProvider authorizationProvider) {
|
||||
super(authorizationProvider);
|
||||
this.organizationName = organizationName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEncodedAuthorization() throws IOException {
|
||||
synchronized (this) {
|
||||
if (latestToken == null || Instant.now().isAfter(this.validUntil)) {
|
||||
refreshToken();
|
||||
}
|
||||
return String.format("token %s", latestToken);
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshToken() throws IOException {
|
||||
GitHub gitHub = this.gitHub();
|
||||
GHAppInstallation installationByOrganization = gitHub.getApp()
|
||||
.getInstallationByOrganization(this.organizationName);
|
||||
GHAppInstallationToken ghAppInstallationToken = installationByOrganization.createToken().create();
|
||||
this.validUntil = ghAppInstallationToken.getExpiresAt().toInstant().minus(Duration.ofMinutes(5));
|
||||
this.latestToken = Objects.requireNonNull(ghAppInstallationToken.getToken());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.kohsuke.github.authorization;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
|
||||
/**
|
||||
* Interface for all user-related authorization providers.
|
||||
*
|
||||
* {@link AuthorizationProvider}s can apply to a number of different account types. This interface applies to providers
|
||||
* for user accounts, ones that have a login or should query the "/user" endpoint for the login matching this
|
||||
* credential.
|
||||
*/
|
||||
public interface UserAuthorizationProvider extends AuthorizationProvider {
|
||||
|
||||
/**
|
||||
* Gets the user login name.
|
||||
*
|
||||
* @return the user login for this provider, or {@code null} if the login value should be queried from the "/user"
|
||||
* endpoint.
|
||||
*/
|
||||
@CheckForNull
|
||||
String getLogin();
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package org.kohsuke.github.extras.authorization;
|
||||
|
||||
import io.jsonwebtoken.JwtBuilder;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import org.kohsuke.github.authorization.AuthorizationProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* A authorization provider that gives valid JWT tokens. These tokens are then used to create a time-based token to
|
||||
* authenticate as an application. This token provider does not provide any kind of caching, and will always request a
|
||||
* new token to the API.
|
||||
*/
|
||||
public class JWTTokenProvider implements AuthorizationProvider {
|
||||
|
||||
private final PrivateKey privateKey;
|
||||
|
||||
@Nonnull
|
||||
private Instant validUntil = Instant.MIN;
|
||||
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* The identifier for the application
|
||||
*/
|
||||
private final String applicationId;
|
||||
|
||||
public JWTTokenProvider(String applicationId, File keyFile) throws GeneralSecurityException, IOException {
|
||||
this(applicationId, keyFile.toPath());
|
||||
}
|
||||
|
||||
public JWTTokenProvider(String applicationId, Path keyPath) throws GeneralSecurityException, IOException {
|
||||
this(applicationId, new String(Files.readAllBytes(keyPath), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public JWTTokenProvider(String applicationId, String keyString) throws GeneralSecurityException {
|
||||
this(applicationId, getPrivateKeyFromString(keyString));
|
||||
}
|
||||
|
||||
public JWTTokenProvider(String applicationId, PrivateKey privateKey) {
|
||||
this.privateKey = privateKey;
|
||||
this.applicationId = applicationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEncodedAuthorization() throws IOException {
|
||||
synchronized (this) {
|
||||
if (Instant.now().isAfter(validUntil)) {
|
||||
token = refreshJWT();
|
||||
}
|
||||
return String.format("Bearer %s", token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a PKCS#8 formatted private key in string format into a java PrivateKey
|
||||
*
|
||||
* @param key
|
||||
* PCKS#8 string
|
||||
* @return private key
|
||||
* @throws GeneralSecurityException
|
||||
* if we couldn't parse the string
|
||||
*/
|
||||
private static PrivateKey getPrivateKeyFromString(final String key) throws GeneralSecurityException {
|
||||
if (key.contains(" RSA ")) {
|
||||
throw new InvalidKeySpecException(
|
||||
"Private key must be a PKCS#8 formatted string, to convert it from PKCS#1 use: "
|
||||
+ "openssl pkcs8 -topk8 -inform PEM -outform PEM -in current-key.pem -out new-key.pem -nocrypt");
|
||||
}
|
||||
|
||||
// Remove all comments and whitespace from PEM
|
||||
// such as "-----BEGIN PRIVATE KEY-----" and newlines
|
||||
String privateKeyContent = key.replaceAll("(?m)^--.*", "").replaceAll("\\s", "");
|
||||
|
||||
KeyFactory kf = KeyFactory.getInstance("RSA");
|
||||
|
||||
try {
|
||||
byte[] decode = Base64.getDecoder().decode(privateKeyContent);
|
||||
PKCS8EncodedKeySpec keySpecPKCS8 = new PKCS8EncodedKeySpec(decode);
|
||||
|
||||
return kf.generatePrivate(keySpecPKCS8);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new InvalidKeySpecException("Failed to decode private key: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private String refreshJWT() {
|
||||
Instant now = Instant.now();
|
||||
|
||||
// Max token expiration is 10 minutes for GitHub
|
||||
// We use a smaller window since we likely will not need more than a few seconds
|
||||
Instant expiration = now.plus(Duration.ofMinutes(8));
|
||||
|
||||
// Setting the issued at to a time in the past to allow for clock skew
|
||||
Instant issuedAt = getIssuedAt(now);
|
||||
|
||||
// Let's set the JWT Claims
|
||||
JwtBuilder builder = Jwts.builder()
|
||||
.setIssuedAt(Date.from(issuedAt))
|
||||
.setExpiration(Date.from(expiration))
|
||||
.setIssuer(this.applicationId)
|
||||
.signWith(privateKey, SignatureAlgorithm.RS256);
|
||||
|
||||
// Token will refresh 2 minutes before it expires
|
||||
validUntil = expiration.minus(Duration.ofMinutes(2));
|
||||
|
||||
// Builds the JWT and serializes it to a compact, URL-safe string
|
||||
return builder.compact();
|
||||
}
|
||||
|
||||
Instant getIssuedAt(Instant now) {
|
||||
return now.minus(Duration.ofMinutes(2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.kohsuke.github.function;
|
||||
|
||||
/**
|
||||
* A functional interface, equivalent to {@link java.util.function.Function} but that allows throwing {@link Throwable}
|
||||
*
|
||||
* @param <T>
|
||||
* the type of input
|
||||
* @param <R>
|
||||
* the type of output
|
||||
* @param <E>
|
||||
* the type of error
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FunctionThrows<T, R, E extends Throwable> {
|
||||
/**
|
||||
* Apply r.
|
||||
*
|
||||
* @param input
|
||||
* the input
|
||||
* @return the r
|
||||
* @throws E
|
||||
* the e
|
||||
*/
|
||||
R apply(T input) throws E;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.kohsuke.github.function;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* A functional interface, equivalent to {@link java.util.function.Function} but that allows throwing {@link Throwable}
|
||||
*
|
||||
* @param <R>
|
||||
* the type to of object to be returned
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface InputStreamFunction<R> extends FunctionThrows<InputStream, R, IOException> {
|
||||
}
|
||||
39
src/main/java/org/kohsuke/github/internal/EnumUtils.java
Normal file
39
src/main/java/org/kohsuke/github/internal/EnumUtils.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package org.kohsuke.github.internal;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Utils for Enums.
|
||||
*/
|
||||
public final class EnumUtils {
|
||||
|
||||
/**
|
||||
* Returns an enum value matching the value if found, null if the value is null and {@code defaultEnum} if the value
|
||||
* cannot be matched to a value of the enum.
|
||||
* <p>
|
||||
* The value is converted to uppercase before being matched to the enum values.
|
||||
*
|
||||
* @param <E>
|
||||
* the type of the enum
|
||||
* @param enumClass
|
||||
* the type of the enum
|
||||
* @param value
|
||||
* the value to interpret
|
||||
* @param defaultEnum
|
||||
* the default enum value if the value doesn't match one of the enum value
|
||||
* @return an enum value or null
|
||||
*/
|
||||
public static <E extends Enum<E>> E getNullableEnumOrDefault(Class<E> enumClass, String value, E defaultEnum) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Enum.valueOf(enumClass, value.toUpperCase(Locale.ROOT));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return defaultEnum;
|
||||
}
|
||||
}
|
||||
|
||||
private EnumUtils() {
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.kohsuke.github;
|
||||
package org.kohsuke.github.internal;
|
||||
|
||||
/**
|
||||
* Provides the media type strings for GitHub API previews
|
||||
@@ -7,7 +7,7 @@ package org.kohsuke.github;
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
enum Previews {
|
||||
public enum Previews {
|
||||
|
||||
/**
|
||||
* Check-runs and check-suites
|
||||
@@ -2,8 +2,14 @@ package org.kohsuke.github;
|
||||
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.kohsuke.github.authorization.AuthorizationProvider;
|
||||
import org.kohsuke.github.extras.authorization.JWTTokenProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
@@ -21,6 +27,26 @@ public class AbstractGHAppInstallationTest extends AbstractGitHubWireMockTest {
|
||||
private static String PRIVATE_KEY_FILE_APP_2 = "/ghapi-test-app-2.private-key.pem";
|
||||
private static String PRIVATE_KEY_FILE_APP_3 = "/ghapi-test-app-3.private-key.pem";
|
||||
|
||||
private static AuthorizationProvider JWT_PROVIDER_1;
|
||||
private static AuthorizationProvider JWT_PROVIDER_2;
|
||||
private static AuthorizationProvider JWT_PROVIDER_3;
|
||||
|
||||
AbstractGHAppInstallationTest() {
|
||||
try {
|
||||
JWT_PROVIDER_1 = new JWTTokenProvider(TEST_APP_ID_1,
|
||||
new File(this.getClass().getResource(PRIVATE_KEY_FILE_APP_1).getFile()));
|
||||
JWT_PROVIDER_2 = new JWTTokenProvider(TEST_APP_ID_2,
|
||||
new File(this.getClass().getResource(PRIVATE_KEY_FILE_APP_2).getFile()).toPath());
|
||||
JWT_PROVIDER_3 = new JWTTokenProvider(TEST_APP_ID_3,
|
||||
new String(
|
||||
Files.readAllBytes(
|
||||
new File(this.getClass().getResource(PRIVATE_KEY_FILE_APP_3).getFile()).toPath()),
|
||||
StandardCharsets.UTF_8));
|
||||
} catch (GeneralSecurityException | IOException e) {
|
||||
throw new RuntimeException("These should never fail", e);
|
||||
}
|
||||
}
|
||||
|
||||
private String createJwtToken(String keyFileResouceName, String appId) {
|
||||
try {
|
||||
String keyPEM = IOUtils.toString(this.getClass().getResource(keyFileResouceName), "US-ASCII")
|
||||
@@ -54,24 +80,25 @@ public class AbstractGHAppInstallationTest extends AbstractGitHubWireMockTest {
|
||||
.findFirst()
|
||||
.get();
|
||||
|
||||
appInstallation
|
||||
.setRoot(getGitHubBuilder().withAppInstallationToken(appInstallation.createToken().create().getToken())
|
||||
.withEndpoint(mockGitHub.apiServer().baseUrl())
|
||||
.build());
|
||||
// TODO: this is odd
|
||||
// appInstallation
|
||||
// .setRoot(getGitHubBuilder().withAppInstallationToken(appInstallation.createToken().create().getToken())
|
||||
// .withEndpoint(mockGitHub.apiServer().baseUrl())
|
||||
// .build());
|
||||
|
||||
return appInstallation;
|
||||
}
|
||||
|
||||
protected GHAppInstallation getAppInstallationWithTokenApp1() throws IOException {
|
||||
return getAppInstallationWithToken(createJwtToken(PRIVATE_KEY_FILE_APP_1, TEST_APP_ID_1));
|
||||
return getAppInstallationWithToken(JWT_PROVIDER_1.getEncodedAuthorization());
|
||||
}
|
||||
|
||||
protected GHAppInstallation getAppInstallationWithTokenApp2() throws IOException {
|
||||
return getAppInstallationWithToken(createJwtToken(PRIVATE_KEY_FILE_APP_2, TEST_APP_ID_2));
|
||||
return getAppInstallationWithToken(JWT_PROVIDER_2.getEncodedAuthorization());
|
||||
}
|
||||
|
||||
protected GHAppInstallation getAppInstallationWithTokenApp3() throws IOException {
|
||||
return getAppInstallationWithToken(createJwtToken(PRIVATE_KEY_FILE_APP_3, TEST_APP_ID_3));
|
||||
return getAppInstallationWithToken(JWT_PROVIDER_3.getEncodedAuthorization());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -100,7 +100,6 @@ public abstract class AbstractGitHubWireMockTest extends Assert {
|
||||
// This sets the user and password to a placeholder for wiremock testing
|
||||
// This makes the tests believe they are running with permissions
|
||||
// The recorded stubs will behave like they running with permissions
|
||||
builder.oauthToken = null;
|
||||
builder.withPassword(STUBBED_USER_LOGIN, STUBBED_USER_PASSWORD);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,7 @@ import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.CoreMatchers.sameInstance;
|
||||
import static org.hamcrest.Matchers.hasProperty;
|
||||
import static org.hamcrest.Matchers.oneOf;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
@@ -37,10 +34,11 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
cleanupUserRepository("github-api-test-rename");
|
||||
cleanupUserRepository(targetName);
|
||||
|
||||
GHRepository r = gitHub.createRepository("github-api-test-rename",
|
||||
"a test repository",
|
||||
"http://github-api.kohsuke.org/",
|
||||
true);
|
||||
GHRepository r = gitHub.createRepository("github-api-test-rename")
|
||||
.description("a test repository")
|
||||
.homepage("http://github-api.kohsuke.org/")
|
||||
.private_(false)
|
||||
.create();
|
||||
|
||||
assertThat(r.hasIssues(), is(true));
|
||||
assertThat(r.hasWiki(), is(true));
|
||||
@@ -137,13 +135,36 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
@Test
|
||||
public void testIssueWithNoComment() throws IOException {
|
||||
GHRepository repository = gitHub.getRepository("kohsuke/test");
|
||||
List<GHIssueComment> v = repository.getIssue(4).getComments();
|
||||
GHIssue i = repository.getIssue(4);
|
||||
List<GHIssueComment> v = i.getComments();
|
||||
// System.out.println(v);
|
||||
assertTrue(v.isEmpty());
|
||||
|
||||
v = repository.getIssue(3).getComments();
|
||||
i = repository.getIssue(3);
|
||||
v = i.getComments();
|
||||
// System.out.println(v);
|
||||
assertTrue(v.size() == 3);
|
||||
assertThat(v.size(), equalTo(3));
|
||||
assertThat(v.get(0).getHtmlUrl().toString(),
|
||||
equalTo("https://github.com/kohsuke/test/issues/3#issuecomment-8547249"));
|
||||
assertThat(v.get(0).getUrl().toString(), endsWith("/repos/kohsuke/test/issues/comments/8547249"));
|
||||
assertThat(v.get(0).getNodeId(), equalTo("MDEyOklzc3VlQ29tbWVudDg1NDcyNDk="));
|
||||
assertThat(v.get(0).getParent().getNumber(), equalTo(3));
|
||||
assertThat(v.get(0).getParent().getId(), equalTo(6863845L));
|
||||
assertThat(v.get(0).getUser().getLogin(), equalTo("kohsuke"));
|
||||
assertThat(v.get(0).listReactions().toList().size(), equalTo(0));
|
||||
|
||||
assertThat(v.get(1).getHtmlUrl().toString(),
|
||||
equalTo("https://github.com/kohsuke/test/issues/3#issuecomment-8547251"));
|
||||
assertThat(v.get(1).getUrl().toString(), endsWith("/repos/kohsuke/test/issues/comments/8547251"));
|
||||
assertThat(v.get(1).getNodeId(), equalTo("MDEyOklzc3VlQ29tbWVudDg1NDcyNTE="));
|
||||
assertThat(v.get(1).getParent().getNumber(), equalTo(3));
|
||||
assertThat(v.get(1).getUser().getLogin(), equalTo("kohsuke"));
|
||||
List<GHReaction> reactions = v.get(1).listReactions().toList();
|
||||
assertThat(reactions.size(), equalTo(3));
|
||||
|
||||
// TODO: Add comment CRUD test
|
||||
// TODO: Add reactions CRUD test
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,49 +186,60 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
@Test
|
||||
public void testCreateAndListDeployments() throws IOException {
|
||||
GHRepository repository = getTestRepository();
|
||||
GHDeployment deployment = repository.createDeployment("master")
|
||||
GHDeployment deployment = repository.createDeployment("main")
|
||||
.payload("{\"user\":\"atmos\",\"room_id\":123456}")
|
||||
.description("question")
|
||||
.environment("unittest")
|
||||
.create();
|
||||
assertNotNull(deployment.getCreator());
|
||||
assertNotNull(deployment.getId());
|
||||
List<GHDeployment> deployments = repository.listDeployments(null, "master", null, "unittest").toList();
|
||||
assertNotNull(deployments);
|
||||
assertFalse(Iterables.isEmpty(deployments));
|
||||
GHDeployment unitTestDeployment = deployments.get(0);
|
||||
assertEquals("unittest", unitTestDeployment.getEnvironment());
|
||||
assertEquals("unittest", unitTestDeployment.getOriginalEnvironment());
|
||||
assertEquals(false, unitTestDeployment.isProductionEnvironment());
|
||||
assertEquals(true, unitTestDeployment.isTransientEnvironment());
|
||||
assertEquals("master", unitTestDeployment.getRef());
|
||||
try {
|
||||
assertNotNull(deployment.getCreator());
|
||||
assertNotNull(deployment.getId());
|
||||
List<GHDeployment> deployments = repository.listDeployments(null, "main", null, "unittest").toList();
|
||||
assertNotNull(deployments);
|
||||
assertFalse(Iterables.isEmpty(deployments));
|
||||
GHDeployment unitTestDeployment = deployments.get(0);
|
||||
assertEquals("unittest", unitTestDeployment.getEnvironment());
|
||||
assertEquals("unittest", unitTestDeployment.getOriginalEnvironment());
|
||||
assertEquals(false, unitTestDeployment.isProductionEnvironment());
|
||||
assertEquals(false, unitTestDeployment.isTransientEnvironment());
|
||||
assertEquals("main", unitTestDeployment.getRef());
|
||||
} finally {
|
||||
// deployment.delete();
|
||||
assert true;
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("Needs mocking check")
|
||||
@Test
|
||||
public void testGetDeploymentStatuses() throws IOException {
|
||||
GHRepository repository = getTestRepository();
|
||||
GHDeployment deployment = repository.createDeployment("master")
|
||||
GHDeployment deployment = repository.createDeployment("main")
|
||||
.description("question")
|
||||
.payload("{\"user\":\"atmos\",\"room_id\":123456}")
|
||||
.create();
|
||||
GHDeploymentStatus ghDeploymentStatus = deployment.createStatus(GHDeploymentState.QUEUED)
|
||||
.description("success")
|
||||
.targetUrl("http://www.github.com")
|
||||
.logUrl("http://www.github.com/logurl")
|
||||
.environmentUrl("http://www.github.com/envurl")
|
||||
.environment("new-ci-env")
|
||||
.create();
|
||||
Iterable<GHDeploymentStatus> deploymentStatuses = deployment.listStatuses();
|
||||
assertNotNull(deploymentStatuses);
|
||||
assertEquals(1, Iterables.size(deploymentStatuses));
|
||||
GHDeploymentStatus actualStatus = Iterables.get(deploymentStatuses, 0);
|
||||
assertEquals(ghDeploymentStatus.getId(), actualStatus.getId());
|
||||
assertEquals(ghDeploymentStatus.getState(), actualStatus.getState());
|
||||
assertEquals(ghDeploymentStatus.getLogUrl(), actualStatus.getLogUrl());
|
||||
// Target url was deprecated and replaced with log url. The gh api will
|
||||
// prefer the log url value and return it in place of target url.
|
||||
assertEquals(ghDeploymentStatus.getTargetUrl(), actualStatus.getLogUrl());
|
||||
try {
|
||||
GHDeploymentStatus ghDeploymentStatus = deployment.createStatus(GHDeploymentState.QUEUED)
|
||||
.description("success")
|
||||
.targetUrl("http://www.github.com")
|
||||
.logUrl("http://www.github.com/logurl")
|
||||
.environmentUrl("http://www.github.com/envurl")
|
||||
.environment("new-ci-env")
|
||||
.create();
|
||||
Iterable<GHDeploymentStatus> deploymentStatuses = deployment.listStatuses();
|
||||
assertNotNull(deploymentStatuses);
|
||||
assertEquals(1, Iterables.size(deploymentStatuses));
|
||||
GHDeploymentStatus actualStatus = Iterables.get(deploymentStatuses, 0);
|
||||
assertEquals(ghDeploymentStatus.getId(), actualStatus.getId());
|
||||
assertEquals(ghDeploymentStatus.getState(), actualStatus.getState());
|
||||
assertEquals(ghDeploymentStatus.getLogUrl(), actualStatus.getLogUrl());
|
||||
// Target url was deprecated and replaced with log url. The gh api will
|
||||
// prefer the log url value and return it in place of target url.
|
||||
assertEquals(ghDeploymentStatus.getTargetUrl(), actualStatus.getLogUrl());
|
||||
assertThat(ghDeploymentStatus.getDeploymentUrl(), equalTo(deployment.getUrl()));
|
||||
assertThat(ghDeploymentStatus.getRepositoryUrl(), equalTo(repository.getUrl()));
|
||||
} finally {
|
||||
// deployment.delete();
|
||||
assert true;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -324,7 +356,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
assertEquals(teamByName.getId(), teamById.getId());
|
||||
assertEquals(teamByName.getDescription(), teamById.getDescription());
|
||||
|
||||
GHTeam teamById2 = organization.getTeam((int) teamByName.getId());
|
||||
GHTeam teamById2 = organization.getTeam(teamByName.getId());
|
||||
assertNotNull(teamById2);
|
||||
|
||||
assertEquals(teamByName.getId(), teamById2.getId());
|
||||
@@ -445,6 +477,16 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
File f = commit.getFiles().get(0);
|
||||
assertEquals(48, f.getLinesChanged());
|
||||
assertThat(f.getLinesAdded(), equalTo(40));
|
||||
assertThat(f.getLinesDeleted(), equalTo(8));
|
||||
assertThat(f.getPreviousFilename(), nullValue());
|
||||
assertThat(f.getPatch(), startsWith("@@ -54,6 +54,14 @@\n"));
|
||||
assertThat(f.getSha(), equalTo("04d3e54017542ad0ff46355eababacd4850ccba5"));
|
||||
assertThat(f.getBlobUrl().toString(),
|
||||
equalTo("https://github.com/jenkinsci/jenkins/blob/08c1c9970af4d609ae754fbe803e06186e3206f7/changelog.html"));
|
||||
assertThat(f.getRawUrl().toString(),
|
||||
equalTo("https://github.com/jenkinsci/jenkins/raw/08c1c9970af4d609ae754fbe803e06186e3206f7/changelog.html"));
|
||||
|
||||
assertEquals("modified", f.getStatus());
|
||||
assertEquals("changelog.html", f.getFileName());
|
||||
|
||||
@@ -464,22 +506,6 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
assertEquals(1, sha1.size());
|
||||
}
|
||||
|
||||
public void testQueryCommits() throws Exception {
|
||||
List<String> sha1 = new ArrayList<String>();
|
||||
for (GHCommit c : gitHub.getUser("jenkinsci")
|
||||
.getRepository("jenkins")
|
||||
.queryCommits()
|
||||
.since(new Date(1199174400000L))
|
||||
.until(1201852800000L)
|
||||
.path("pom.xml")
|
||||
.list()) {
|
||||
// System.out.println(c.getSHA1());
|
||||
sha1.add(c.getSHA1());
|
||||
}
|
||||
assertEquals("1cccddb22e305397151b2b7b87b4b47d74ca337b", sha1.get(0));
|
||||
assertEquals(29, sha1.size());
|
||||
}
|
||||
|
||||
@Ignore("Needs mocking check")
|
||||
@Test
|
||||
public void testBranches() throws Exception {
|
||||
@@ -504,23 +530,65 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
.getRepository("sandbox-ant")
|
||||
.getCommit("8ae38db0ea5837313ab5f39d43a6f73de3bd9000");
|
||||
GHCommitComment c = commit.createComment("[testing](http://kohsuse.org/)");
|
||||
// System.out.println(c);
|
||||
c.update("updated text");
|
||||
// System.out.println(c);
|
||||
c.delete();
|
||||
try {
|
||||
assertThat(c.getPath(), nullValue());
|
||||
assertThat(c.getLine(), equalTo(-1));
|
||||
assertThat(c.getHtmlUrl().toString(),
|
||||
containsString(
|
||||
"kohsuke/sandbox-ant/commit/8ae38db0ea5837313ab5f39d43a6f73de3bd9000#commitcomment-"));
|
||||
assertThat(c.listReactions().toList(), is(empty()));
|
||||
|
||||
c.update("updated text");
|
||||
assertThat(c.getBody(), equalTo("updated text"));
|
||||
} finally {
|
||||
c.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tryHook() throws Exception {
|
||||
kohsuke();
|
||||
GHRepository r = gitHub.getOrganization(GITHUB_API_TEST_ORG).getRepository("github-api");
|
||||
GHHook hook = r.createWebHook(new URL("http://www.google.com/"));
|
||||
// System.out.println(hook);
|
||||
GHOrganization o = gitHub.getOrganization(GITHUB_API_TEST_ORG);
|
||||
GHRepository r = o.getRepository("github-api");
|
||||
try {
|
||||
GHHook hook = r.createWebHook(new URL("http://www.google.com/"));
|
||||
assertThat(hook.getName(), equalTo("web"));
|
||||
assertThat(hook.getEvents().size(), equalTo(1));
|
||||
assertThat(hook.getEvents(), contains(GHEvent.PUSH));
|
||||
assertThat(hook.getConfig().size(), equalTo(3));
|
||||
assertThat(hook.isActive(), equalTo(true));
|
||||
|
||||
if (mockGitHub.isUseProxy()) {
|
||||
r = getGitHubBeforeAfter().getOrganization(GITHUB_API_TEST_ORG).getRepository("github-api");
|
||||
for (GHHook h : r.getHooks()) {
|
||||
h.delete();
|
||||
GHHook hook2 = r.getHook((int) hook.getId());
|
||||
assertThat(hook2.getName(), equalTo("web"));
|
||||
assertThat(hook2.getEvents().size(), equalTo(1));
|
||||
assertThat(hook2.getEvents(), contains(GHEvent.PUSH));
|
||||
assertThat(hook2.getConfig().size(), equalTo(3));
|
||||
assertThat(hook2.isActive(), equalTo(true));
|
||||
hook2.ping();
|
||||
hook2.delete();
|
||||
|
||||
hook = o.createWebHook(new URL("http://www.google.com/"));
|
||||
assertThat(hook.getName(), equalTo("web"));
|
||||
assertThat(hook.getEvents().size(), equalTo(1));
|
||||
assertThat(hook.getEvents(), contains(GHEvent.PUSH));
|
||||
assertThat(hook.getConfig().size(), equalTo(3));
|
||||
assertThat(hook.isActive(), equalTo(true));
|
||||
|
||||
hook2 = o.getHook((int) hook.getId());
|
||||
assertThat(hook2.getName(), equalTo("web"));
|
||||
assertThat(hook2.getEvents().size(), equalTo(1));
|
||||
assertThat(hook2.getEvents(), contains(GHEvent.PUSH));
|
||||
assertThat(hook2.getConfig().size(), equalTo(3));
|
||||
assertThat(hook2.isActive(), equalTo(true));
|
||||
hook2.ping();
|
||||
hook2.delete();
|
||||
|
||||
// System.out.println(hook);
|
||||
} finally {
|
||||
if (mockGitHub.isUseProxy()) {
|
||||
r = getGitHubBeforeAfter().getOrganization(GITHUB_API_TEST_ORG).getRepository("github-api");
|
||||
for (GHHook h : r.getHooks()) {
|
||||
h.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -529,6 +597,14 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
public void testEventApi() throws Exception {
|
||||
for (GHEventInfo ev : gitHub.getEvents()) {
|
||||
if (ev.getType() == GHEvent.PULL_REQUEST) {
|
||||
if (ev.getId() == 10680625394L) {
|
||||
assertThat(ev.getActorLogin(), equalTo("pull[bot]"));
|
||||
assertThat(ev.getOrganization(), nullValue());
|
||||
assertThat(ev.getRepository().getFullName(), equalTo("daddyfatstacksBIG/lerna"));
|
||||
assertThat(ev.getCreatedAt(), equalTo(GitHubClient.parseDate("2019-10-21T21:54:52Z")));
|
||||
assertThat(ev.getType(), equalTo(GHEvent.PULL_REQUEST));
|
||||
}
|
||||
|
||||
GHEventPayload.PullRequest pr = ev.getPayload(GHEventPayload.PullRequest.class);
|
||||
assertThat(pr.getNumber(), is(pr.getPullRequest().getNumber()));
|
||||
}
|
||||
@@ -859,8 +935,18 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
for (GHTreeEntry e : masterTree.getTree()) {
|
||||
if (e.getPath().endsWith(AppTest.class.getSimpleName() + ".java")) {
|
||||
foundThisFile = true;
|
||||
assertThat(e.getPath(), equalTo("src/test/java/org/kohsuke/github/AppTest.java"));
|
||||
assertThat(e.getSha(), equalTo("baad7a7c4cf409f610a0e8c7eba17664eb655c44"));
|
||||
assertThat(e.getMode(), equalTo("100755"));
|
||||
assertThat(e.getSize(), greaterThan(30000L));
|
||||
assertThat(e.getUrl().toString(),
|
||||
containsString("/repos/hub4j/github-api/git/blobs/baad7a7c4cf409f610a0e8c7eba17664eb655c44"));
|
||||
GHBlob blob = e.asBlob();
|
||||
assertThat(e.asBlob().getUrl().toString(),
|
||||
containsString("/repos/hub4j/github-api/git/blobs/baad7a7c4cf409f610a0e8c7eba17664eb655c44"));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
assertTrue(foundThisFile);
|
||||
}
|
||||
@@ -879,6 +965,9 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
GHLabel e = r.getLabel("enhancement");
|
||||
assertEquals("enhancement", e.getName());
|
||||
assertNotNull(e.getUrl());
|
||||
assertEquals(177339106, e.getId());
|
||||
assertEquals("MDU6TGFiZWwxNzczMzkxMDY=", e.getNodeId());
|
||||
assertTrue(e.isDefault());
|
||||
assertTrue(Pattern.matches("[0-9a-fA-F]{6}", e.getColor()));
|
||||
|
||||
GHLabel t = null;
|
||||
@@ -890,12 +979,17 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
assertThat(t, not(sameInstance(t2)));
|
||||
assertThat(t, equalTo(t2));
|
||||
|
||||
assertFalse(t2.isDefault());
|
||||
|
||||
assertEquals(t.getId(), t2.getId());
|
||||
assertEquals(t.getNodeId(), t2.getNodeId());
|
||||
assertEquals(t.getName(), t2.getName());
|
||||
assertEquals(t.getColor(), "123456");
|
||||
assertEquals(t.getColor(), t2.getColor());
|
||||
assertEquals(t.getDescription(), "");
|
||||
assertEquals(t.getDescription(), t2.getDescription());
|
||||
assertEquals(t.getUrl(), t2.getUrl());
|
||||
assertEquals(t.isDefault(), t2.isDefault());
|
||||
|
||||
// update works on multiple changes in one call
|
||||
t3 = t.update().color("000000").description("It is dark!").done();
|
||||
|
||||
@@ -33,6 +33,7 @@ public class BridgeMethodTest extends Assert {
|
||||
verifyBridgeMethods(GHIssue.class, "getCreatedAt", Date.class, String.class);
|
||||
verifyBridgeMethods(GHIssue.class, "getId", int.class, long.class, String.class);
|
||||
verifyBridgeMethods(GHIssue.class, "getUrl", String.class, URL.class);
|
||||
verifyBridgeMethods(GHIssue.class, "comment", 1, void.class, GHIssueComment.class);
|
||||
|
||||
verifyBridgeMethods(GHOrganization.class, "getHtmlUrl", String.class, URL.class);
|
||||
verifyBridgeMethods(GHOrganization.class, "getId", int.class, long.class, String.class);
|
||||
@@ -55,12 +56,17 @@ public class BridgeMethodTest extends Assert {
|
||||
}
|
||||
|
||||
void verifyBridgeMethods(@Nonnull Class<?> targetClass, @Nonnull String methodName, Class<?>... returnTypes) {
|
||||
verifyBridgeMethods(targetClass, methodName, 0, returnTypes);
|
||||
}
|
||||
|
||||
void verifyBridgeMethods(@Nonnull Class<?> targetClass,
|
||||
@Nonnull String methodName,
|
||||
int parameterCount,
|
||||
Class<?>... returnTypes) {
|
||||
List<Class<?>> foundMethods = new ArrayList<>();
|
||||
Method[] methods = targetClass.getMethods();
|
||||
for (Method method : methods) {
|
||||
if (method.getName().equalsIgnoreCase(methodName)) {
|
||||
// Bridge methods are only
|
||||
assertThat(method.getParameterCount(), equalTo(0));
|
||||
if (method.getName().equalsIgnoreCase(methodName) && method.getParameterCount() == parameterCount) {
|
||||
foundMethods.add(method.getReturnType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ import com.google.common.collect.Iterables;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
@@ -29,6 +31,85 @@ public class CommitTest extends AbstractGitHubWireMockTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryCommits() throws Exception {
|
||||
List<String> sha1 = new ArrayList<String>();
|
||||
List<GHCommit> commits = gitHub.getUser("jenkinsci")
|
||||
.getRepository("jenkins")
|
||||
.queryCommits()
|
||||
.since(1199174400000L)
|
||||
.until(1201852800000L)
|
||||
.path("pom.xml")
|
||||
.pageSize(100)
|
||||
.list()
|
||||
.toList();
|
||||
|
||||
assertThat(commits.get(0).getSHA1(), equalTo("1cccddb22e305397151b2b7b87b4b47d74ca337b"));
|
||||
assertThat(commits.size(), equalTo(29));
|
||||
|
||||
commits = gitHub.getUser("jenkinsci")
|
||||
.getRepository("jenkins")
|
||||
.queryCommits()
|
||||
.since(new Date(1199174400000L))
|
||||
.until(new Date(1201852800000L))
|
||||
.path("pom.xml")
|
||||
.pageSize(100)
|
||||
.list()
|
||||
.toList();
|
||||
|
||||
assertThat(commits.get(0).getSHA1(), equalTo("1cccddb22e305397151b2b7b87b4b47d74ca337b"));
|
||||
assertThat(commits.get(15).getSHA1(), equalTo("a5259970acaec9813e2a12a91f37dfc7871a5ef5"));
|
||||
assertThat(commits.size(), equalTo(29));
|
||||
|
||||
commits = gitHub.getUser("jenkinsci")
|
||||
.getRepository("jenkins")
|
||||
.queryCommits()
|
||||
.since(new Date(1199174400000L))
|
||||
.until(new Date(1201852800000L))
|
||||
.path("pom.xml")
|
||||
.from("a5259970acaec9813e2a12a91f37dfc7871a5ef5")
|
||||
.list()
|
||||
.toList();
|
||||
|
||||
assertThat(commits.get(0).getSHA1(), equalTo("a5259970acaec9813e2a12a91f37dfc7871a5ef5"));
|
||||
assertThat(commits.size(), equalTo(14));
|
||||
|
||||
commits = gitHub.getUser("jenkinsci")
|
||||
.getRepository("jenkins")
|
||||
.queryCommits()
|
||||
.until(new Date(1201852800000L))
|
||||
.path("pom.xml")
|
||||
.author("kohsuke")
|
||||
.list()
|
||||
.toList();
|
||||
|
||||
assertThat(commits.size(), equalTo(0));
|
||||
|
||||
commits = gitHub.getUser("jenkinsci")
|
||||
.getRepository("jenkins")
|
||||
.queryCommits()
|
||||
.until(new Date(1201852800000L))
|
||||
.path("pom.xml")
|
||||
.pageSize(100)
|
||||
.author("kohsuke@71c3de6d-444a-0410-be80-ed276b4c234a")
|
||||
.list()
|
||||
.toList();
|
||||
|
||||
assertThat(commits.size(), equalTo(266));
|
||||
|
||||
commits = gitHub.getUser("jenkinsci")
|
||||
.getRepository("jenkins")
|
||||
.queryCommits()
|
||||
.path("pom.xml")
|
||||
.pageSize(100)
|
||||
.author("kohsuke@71c3de6d-444a-0410-be80-ed276b4c234a")
|
||||
.list()
|
||||
.toList();
|
||||
|
||||
assertThat(commits.size(), equalTo(648));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listPullRequestsOfNotIncludedCommit() throws Exception {
|
||||
GHRepository repo = gitHub.getOrganization("hub4j-test-org").getRepository("listPrsListHeads");
|
||||
|
||||
84
src/test/java/org/kohsuke/github/EnumTest.java
Normal file
84
src/test/java/org/kohsuke/github/EnumTest.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
|
||||
/**
|
||||
* Unit test for {@link GitHub} static helpers.
|
||||
*
|
||||
* @author Liam Newman
|
||||
*/
|
||||
public class EnumTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
@Test
|
||||
public void touchEnums() {
|
||||
assertThat(GHCheckRun.AnnotationLevel.values().length, equalTo(3));
|
||||
assertThat(GHCheckRun.Conclusion.values().length, equalTo(9));
|
||||
assertThat(GHCheckRun.Status.values().length, equalTo(4));
|
||||
|
||||
assertThat(GHCommentAuthorAssociation.values().length, equalTo(7));
|
||||
|
||||
assertThat(GHCommitState.values().length, equalTo(4));
|
||||
|
||||
assertThat(GHCompare.Status.values().length, equalTo(4));
|
||||
|
||||
assertThat(GHDeploymentState.values().length, equalTo(7));
|
||||
|
||||
assertThat(GHDirection.values().length, equalTo(2));
|
||||
|
||||
assertThat(GHEvent.values().length, equalTo(56));
|
||||
assertThat(GHEvent.ALL.symbol(), equalTo("*"));
|
||||
assertThat(GHEvent.PULL_REQUEST.symbol(), equalTo(GHEvent.PULL_REQUEST.toString().toLowerCase()));
|
||||
|
||||
assertThat(GHIssueSearchBuilder.Sort.values().length, equalTo(3));
|
||||
|
||||
assertThat(GHIssueState.values().length, equalTo(3));
|
||||
|
||||
assertThat(GHMarketplaceAccountType.values().length, equalTo(2));
|
||||
|
||||
assertThat(GHMarketplaceListAccountBuilder.Sort.values().length, equalTo(2));
|
||||
|
||||
assertThat(GHMarketplacePriceModel.values().length, equalTo(3));
|
||||
|
||||
assertThat(GHMembership.Role.values().length, equalTo(2));
|
||||
|
||||
assertThat(GHMilestoneState.values().length, equalTo(2));
|
||||
|
||||
assertThat(GHMyself.RepositoryListFilter.values().length, equalTo(5));
|
||||
|
||||
assertThat(GHOrganization.Role.values().length, equalTo(2));
|
||||
assertThat(GHOrganization.Permission.values().length, equalTo(5));
|
||||
|
||||
assertThat(GHPermissionType.values().length, equalTo(4));
|
||||
|
||||
assertThat(GHProject.ProjectState.values().length, equalTo(2));
|
||||
assertThat(GHProject.ProjectStateFilter.values().length, equalTo(3));
|
||||
|
||||
assertThat(GHPullRequest.MergeMethod.values().length, equalTo(3));
|
||||
|
||||
assertThat(GHPullRequestQueryBuilder.Sort.values().length, equalTo(4));
|
||||
|
||||
assertThat(GHPullRequestReviewEvent.values().length, equalTo(4));
|
||||
assertThat(GHPullRequestReviewEvent.PENDING.toState(), equalTo(GHPullRequestReviewState.PENDING));
|
||||
assertThat(GHPullRequestReviewEvent.PENDING.action(), nullValue());
|
||||
|
||||
assertThat(GHPullRequestReviewState.values().length, equalTo(6));
|
||||
assertThat(GHPullRequestReviewState.PENDING.toEvent(), equalTo(GHPullRequestReviewEvent.PENDING));
|
||||
assertThat(GHPullRequestReviewState.APPROVED.action(), equalTo(GHPullRequestReviewEvent.APPROVE.action()));
|
||||
assertThat(GHPullRequestReviewState.DISMISSED.toEvent(), nullValue());
|
||||
|
||||
assertThat(GHRepository.CollaboratorAffiliation.values().length, equalTo(3));
|
||||
assertThat(GHRepository.ForkSort.values().length, equalTo(3));
|
||||
|
||||
assertThat(GHRepositorySearchBuilder.Sort.values().length, equalTo(3));
|
||||
|
||||
assertThat(GHRepositorySelection.values().length, equalTo(2));
|
||||
|
||||
assertThat(GHTeam.Role.values().length, equalTo(2));
|
||||
assertThat(GHTeam.Privacy.values().length, equalTo(2));
|
||||
|
||||
assertThat(GHUserSearchBuilder.Sort.values().length, equalTo(3));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -103,7 +103,8 @@ public class GHAppTest extends AbstractGitHubWireMockTest {
|
||||
permissions.put("metadata", GHPermissionType.READ);
|
||||
|
||||
// Create token specifying both permissions and repository ids
|
||||
GHAppInstallationToken installationToken = installation.createToken(permissions)
|
||||
GHAppInstallationToken installationToken = installation.createToken()
|
||||
.permissions(permissions)
|
||||
.repositoryIds(Collections.singletonList((long) 111111111))
|
||||
.create();
|
||||
|
||||
|
||||
@@ -25,11 +25,13 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.kohsuke.github.GHCheckRun.Status;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@SuppressWarnings("deprecation") // preview
|
||||
public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
|
||||
@@ -48,7 +50,7 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
|
||||
.withExternalID("whatever")
|
||||
.withStartedAt(new Date(999_999_000))
|
||||
.withCompletedAt(new Date(999_999_999))
|
||||
.add(new GHCheckRunBuilder.Output("Some Title", "what happened…")
|
||||
.add(new GHCheckRunBuilder.Output("Some Title", "what happened…").withText("Hello Text!")
|
||||
.add(new GHCheckRunBuilder.Annotation("stuff.txt",
|
||||
1,
|
||||
GHCheckRun.AnnotationLevel.NOTICE,
|
||||
@@ -58,14 +60,17 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
|
||||
.withCaption("Princess Unikitty")))
|
||||
.add(new GHCheckRunBuilder.Action("Help", "what I need help with", "doit"))
|
||||
.create();
|
||||
assertEquals("completed", checkRun.getStatus());
|
||||
assertEquals(Status.COMPLETED, checkRun.getStatus());
|
||||
assertEquals(1, checkRun.getOutput().getAnnotationsCount());
|
||||
assertEquals(1424883286, checkRun.getId());
|
||||
assertEquals("Hello Text!", checkRun.getOutput().getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createCheckRunManyAnnotations() throws Exception {
|
||||
GHCheckRunBuilder.Output output = new GHCheckRunBuilder.Output("Big Run", "Lots of stuff here »");
|
||||
GHCheckRunBuilder.Output output = new GHCheckRunBuilder.Output("Big Run", "Lots of stuff here »")
|
||||
.withText("Hello Text!");
|
||||
|
||||
for (int i = 0; i < 101; i++) {
|
||||
output.add(
|
||||
new GHCheckRunBuilder.Annotation("stuff.txt", 1, GHCheckRun.AnnotationLevel.NOTICE, "hello #" + i));
|
||||
@@ -75,10 +80,11 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
|
||||
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
|
||||
.add(output)
|
||||
.create();
|
||||
assertEquals("completed", checkRun.getStatus());
|
||||
assertEquals(Status.COMPLETED, checkRun.getStatus());
|
||||
assertEquals("Big Run", checkRun.getOutput().getTitle());
|
||||
assertEquals("Lots of stuff here »", checkRun.getOutput().getSummary());
|
||||
assertEquals(101, checkRun.getOutput().getAnnotationsCount());
|
||||
assertEquals("Hello Text!", checkRun.getOutput().getText());
|
||||
assertEquals(1424883599, checkRun.getId());
|
||||
}
|
||||
|
||||
@@ -89,7 +95,7 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
|
||||
.withConclusion(GHCheckRun.Conclusion.NEUTRAL)
|
||||
.add(new GHCheckRunBuilder.Output("Quick note", "nothing more to see here"))
|
||||
.create();
|
||||
assertEquals("completed", checkRun.getStatus());
|
||||
assertEquals(Status.COMPLETED, checkRun.getStatus());
|
||||
assertEquals(0, checkRun.getOutput().getAnnotationsCount());
|
||||
assertEquals(1424883957, checkRun.getId());
|
||||
}
|
||||
@@ -100,7 +106,7 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
|
||||
.createCheckRun("outstanding", "89a9ae301e35e667756034fdc933b1fc94f63fc1")
|
||||
.withStatus(GHCheckRun.Status.IN_PROGRESS)
|
||||
.create();
|
||||
assertEquals("in_progress", checkRun.getStatus());
|
||||
assertEquals(Status.IN_PROGRESS, checkRun.getStatus());
|
||||
assertNull(checkRun.getConclusion());
|
||||
assertEquals(1424883451, checkRun.getId());
|
||||
}
|
||||
@@ -116,6 +122,8 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
|
||||
} catch (HttpException x) {
|
||||
assertEquals(422, x.getResponseCode());
|
||||
assertThat(x.getMessage(), containsString("\\\"conclusion\\\" wasn't supplied"));
|
||||
assertThat(x.getUrl(), containsString("/repos/hub4j-test-org/test-checks/check-runs"));
|
||||
assertThat(x.getResponseMessage(), equalTo("422 Unprocessable Entity"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,14 @@ public class GHContentIntegrationTest extends AbstractGitHubWireMockTest {
|
||||
repo = gitHub.getRepository("hub4j-test-org/GHContentIntegrationTest");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRepository() throws Exception {
|
||||
GHRepository testRepo = gitHub.getRepositoryById(repo.getId());
|
||||
assertThat(testRepo.getName(), equalTo(repo.getName()));
|
||||
testRepo = gitHub.getRepositoryById(Long.toString(repo.getId()));
|
||||
assertThat(testRepo.getName(), equalTo(repo.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFileContent() throws Exception {
|
||||
repo = gitHub.getRepository("hub4j-test-org/GHContentIntegrationTest");
|
||||
|
||||
@@ -2,14 +2,26 @@ package org.kohsuke.github;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.kohsuke.github.GHCheckRun.Conclusion;
|
||||
import org.kohsuke.github.GHCheckRun.Status;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static java.lang.Boolean.TRUE;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.aMapWithSize;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasToString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
public class GHEventPayloadTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
@@ -141,6 +153,45 @@ public class GHEventPayloadTest extends AbstractGitHubWireMockTest {
|
||||
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void issue_labeled() throws Exception {
|
||||
GHEventPayload.Issue event = GitHub.offline().parseEventPayload(payload.asReader(), GHEventPayload.Issue.class);
|
||||
assertThat(event.getAction(), is("labeled"));
|
||||
assertThat(event.getIssue().getNumber(), is(42));
|
||||
assertThat(event.getIssue().getTitle(), is("Test GHEventPayload.Issue label/unlabel"));
|
||||
assertThat(event.getIssue().getLabels().size(), is(1));
|
||||
assertThat(event.getIssue().getLabels().iterator().next().getName(), is("enhancement"));
|
||||
assertThat(event.getLabel().getName(), is("enhancement"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void issue_unlabeled() throws Exception {
|
||||
GHEventPayload.Issue event = GitHub.offline().parseEventPayload(payload.asReader(), GHEventPayload.Issue.class);
|
||||
assertThat(event.getAction(), is("unlabeled"));
|
||||
assertThat(event.getIssue().getNumber(), is(42));
|
||||
assertThat(event.getIssue().getTitle(), is("Test GHEventPayload.Issue label/unlabel"));
|
||||
assertThat(event.getIssue().getLabels().size(), is(0));
|
||||
assertThat(event.getLabel().getName(), is("enhancement"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void issue_title_edited() throws Exception {
|
||||
GHEventPayload.Issue event = GitHub.offline().parseEventPayload(payload.asReader(), GHEventPayload.Issue.class);
|
||||
assertThat(event.getAction(), is("edited"));
|
||||
assertThat(event.getIssue().getNumber(), is(43));
|
||||
assertThat(event.getIssue().getTitle(), is("Test GHEventPayload.Issue changes [updated]"));
|
||||
assertThat(event.getChanges().getTitle().getFrom(), is("Test GHEventPayload.Issue changes"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void issue_body_edited() throws Exception {
|
||||
GHEventPayload.Issue event = GitHub.offline().parseEventPayload(payload.asReader(), GHEventPayload.Issue.class);
|
||||
assertThat(event.getAction(), is("edited"));
|
||||
assertThat(event.getIssue().getNumber(), is(43));
|
||||
assertThat(event.getIssue().getBody(), is("Description [updated]."));
|
||||
assertThat(event.getChanges().getBody().getFrom(), is("Description."));
|
||||
}
|
||||
|
||||
// TODO implement support classes and write test
|
||||
// @Test
|
||||
// public void label() throws Exception {}
|
||||
@@ -361,6 +412,9 @@ public class GHEventPayloadTest extends AbstractGitHubWireMockTest {
|
||||
assertThat(event.getCommits().get(0).getRemoved().size(), is(0));
|
||||
assertThat(event.getCommits().get(0).getModified().size(), is(1));
|
||||
assertThat(event.getCommits().get(0).getModified().get(0), is("README.md"));
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
assertThat(formatter.format(event.getCommits().get(0).getTimestamp()), is("2015-05-05T23:40:15Z"));
|
||||
assertThat(event.getRepository().getName(), is("public-repo"));
|
||||
assertThat(event.getRepository().getOwnerName(), is("baxterthehacker"));
|
||||
assertThat(event.getRepository().getUrl().toExternalForm(),
|
||||
@@ -515,12 +569,13 @@ public class GHEventPayloadTest extends AbstractGitHubWireMockTest {
|
||||
assertThat(event.getRepository().getName(), is("Hello-World"));
|
||||
assertThat(event.getRepository().getOwner().getLogin(), is("Codertocat"));
|
||||
assertThat(event.getAction(), is("created"));
|
||||
assertThat(event.getRequestedAction(), nullValue());
|
||||
|
||||
// Checks the deserialization of check_run
|
||||
GHCheckRun checkRun = event.getCheckRun();
|
||||
assertThat(checkRun.getName(), is("Octocoders-linter"));
|
||||
assertThat(checkRun.getHeadSha(), is("ec26c3e57ca3a959ca5aad62de7213c562f8c821"));
|
||||
assertThat(checkRun.getStatus(), is("completed"));
|
||||
assertThat(checkRun.getStatus(), is(Status.COMPLETED));
|
||||
assertThat(checkRun.getNodeId(), is("MDg6Q2hlY2tSdW4xMjg2MjAyMjg="));
|
||||
assertThat(checkRun.getExternalId(), is(""));
|
||||
|
||||
@@ -529,7 +584,7 @@ public class GHEventPayloadTest extends AbstractGitHubWireMockTest {
|
||||
assertThat(formatter.format(checkRun.getStartedAt()), is("2019-05-15T15:21:12Z"));
|
||||
assertThat(formatter.format(checkRun.getCompletedAt()), is("2019-05-15T20:22:22Z"));
|
||||
|
||||
assertThat(checkRun.getConclusion(), is("success"));
|
||||
assertThat(checkRun.getConclusion(), is(Conclusion.SUCCESS));
|
||||
assertThat(checkRun.getUrl().toString(), endsWith("/repos/Codertocat/Hello-World/check-runs/128620228"));
|
||||
assertThat(checkRun.getHtmlUrl().toString(),
|
||||
endsWith("https://github.com/Codertocat/Hello-World/runs/128620228"));
|
||||
@@ -650,4 +705,104 @@ public class GHEventPayloadTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
assertThat(event.getSender().getLogin(), is("octocat"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void workflow_dispatch() throws Exception {
|
||||
GHEventPayload.WorkflowDispatch workflowDispatchPayload = GitHub.offline()
|
||||
.parseEventPayload(payload.asReader(), GHEventPayload.WorkflowDispatch.class);
|
||||
|
||||
assertThat(workflowDispatchPayload.getRef(), is("refs/heads/main"));
|
||||
assertThat(workflowDispatchPayload.getAction(), is(nullValue()));
|
||||
assertThat(workflowDispatchPayload.getWorkflow(), is(".github/workflows/main.yml"));
|
||||
assertThat(workflowDispatchPayload.getInputs(), aMapWithSize(1));
|
||||
assertThat(workflowDispatchPayload.getInputs().keySet(), contains("logLevel"));
|
||||
assertThat(workflowDispatchPayload.getInputs().values(), contains("warning"));
|
||||
assertThat(workflowDispatchPayload.getRepository().getName(), is("quarkus-bot-java-playground"));
|
||||
assertThat(workflowDispatchPayload.getSender().getLogin(), is("gsmet"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void workflow_run() throws Exception {
|
||||
GHEventPayload.WorkflowRun workflowRunPayload = GitHub.offline()
|
||||
.parseEventPayload(payload.asReader(), GHEventPayload.WorkflowRun.class);
|
||||
|
||||
assertThat(workflowRunPayload.getAction(), is("completed"));
|
||||
assertThat(workflowRunPayload.getRepository().getFullName(), is("gsmet/quarkus-bot-java-playground"));
|
||||
assertThat(workflowRunPayload.getSender().getLogin(), is("gsmet"));
|
||||
|
||||
GHWorkflow workflow = workflowRunPayload.getWorkflow();
|
||||
assertThat(workflow.getId(), is(7087581L));
|
||||
assertThat(workflow.getName(), is("CI"));
|
||||
assertThat(workflow.getPath(), is(".github/workflows/main.yml"));
|
||||
assertThat(workflow.getState(), is("active"));
|
||||
assertThat(workflow.getUrl().toString(),
|
||||
is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/actions/workflows/7087581"));
|
||||
assertThat(workflow.getHtmlUrl().toString(),
|
||||
is("https://github.com/gsmet/quarkus-bot-java-playground/blob/main/.github/workflows/main.yml"));
|
||||
assertThat(workflow.getBadgeUrl().toString(),
|
||||
is("https://github.com/gsmet/quarkus-bot-java-playground/workflows/CI/badge.svg"));
|
||||
|
||||
GHWorkflowRun workflowRun = workflowRunPayload.getWorkflowRun();
|
||||
assertThat(workflowRun.getId(), is(680604745L));
|
||||
assertThat(workflowRun.getName(), is("CI"));
|
||||
assertThat(workflowRun.getHeadBranch(), is("main"));
|
||||
assertThat(workflowRun.getHeadSha(), is("dbea8d8b6ed2cf764dfd84a215f3f9040b3d4423"));
|
||||
assertThat(workflowRun.getRunNumber(), is(6L));
|
||||
assertThat(workflowRun.getEvent(), is(GHEvent.WORKFLOW_DISPATCH));
|
||||
assertThat(workflowRun.getStatus(), is(GHWorkflowRun.Status.COMPLETED));
|
||||
assertThat(workflowRun.getConclusion(), is(GHWorkflowRun.Conclusion.SUCCESS));
|
||||
assertThat(workflowRun.getWorkflowId(), is(7087581L));
|
||||
assertThat(workflowRun.getUrl().toString(),
|
||||
is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/actions/runs/680604745"));
|
||||
assertThat(workflowRun.getHtmlUrl().toString(),
|
||||
is("https://github.com/gsmet/quarkus-bot-java-playground/actions/runs/680604745"));
|
||||
assertThat(workflowRun.getJobsUrl().toString(),
|
||||
is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/actions/runs/680604745/jobs"));
|
||||
assertThat(workflowRun.getLogsUrl().toString(),
|
||||
is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/actions/runs/680604745/logs"));
|
||||
assertThat(workflowRun.getCheckSuiteUrl().toString(),
|
||||
is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/check-suites/2327154397"));
|
||||
assertThat(workflowRun.getArtifactsUrl().toString(),
|
||||
is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/actions/runs/680604745/artifacts"));
|
||||
assertThat(workflowRun.getCancelUrl().toString(),
|
||||
is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/actions/runs/680604745/cancel"));
|
||||
assertThat(workflowRun.getRerunUrl().toString(),
|
||||
is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/actions/runs/680604745/rerun"));
|
||||
assertThat(workflowRun.getWorkflowUrl().toString(),
|
||||
is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/actions/workflows/7087581"));
|
||||
assertThat(workflowRun.getCreatedAt().getTime(), is(1616524526000L));
|
||||
assertThat(workflowRun.getUpdatedAt().getTime(), is(1616524543000L));
|
||||
assertThat(workflowRun.getHeadCommit().getId(), is("dbea8d8b6ed2cf764dfd84a215f3f9040b3d4423"));
|
||||
assertThat(workflowRun.getHeadCommit().getTreeId(), is("b17089e6a2574ec1002566fe980923e62dce3026"));
|
||||
assertThat(workflowRun.getHeadCommit().getMessage(), is("Update main.yml"));
|
||||
assertThat(workflowRun.getHeadCommit().getTimestamp().getTime(), is(1616523390000L));
|
||||
assertThat(workflowRun.getHeadCommit().getAuthor().getName(), is("Guillaume Smet"));
|
||||
assertThat(workflowRun.getHeadCommit().getAuthor().getEmail(), is("guillaume.smet@gmail.com"));
|
||||
assertThat(workflowRun.getHeadCommit().getCommitter().getName(), is("GitHub"));
|
||||
assertThat(workflowRun.getHeadCommit().getCommitter().getEmail(), is("noreply@github.com"));
|
||||
assertThat(workflowRun.getHeadRepository().getFullName(), is("gsmet/quarkus-bot-java-playground"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void workflow_run_pull_request() throws Exception {
|
||||
GHEventPayload.WorkflowRun workflowRunPayload = GitHub.offline()
|
||||
.parseEventPayload(payload.asReader(), GHEventPayload.WorkflowRun.class);
|
||||
|
||||
List<GHPullRequest> pullRequests = workflowRunPayload.getWorkflowRun().getPullRequests();
|
||||
assertThat(pullRequests.size(), is(1));
|
||||
|
||||
GHPullRequest pullRequest = pullRequests.get(0);
|
||||
assertThat(pullRequest.getId(), is(599098265L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void workflow_run_other_repository() throws Exception {
|
||||
GHEventPayload.WorkflowRun workflowRunPayload = GitHub.offline()
|
||||
.parseEventPayload(payload.asReader(), GHEventPayload.WorkflowRun.class);
|
||||
GHWorkflowRun workflowRun = workflowRunPayload.getWorkflowRun();
|
||||
|
||||
assertThat(workflowRunPayload.getRepository().getFullName(), is("gsmet/quarkus-bot-java-playground"));
|
||||
assertThat(workflowRun.getHeadRepository().getFullName(),
|
||||
is("gsmet-bot-playground/quarkus-bot-java-playground"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class GHIssueEventTest extends AbstractGitHubWireMockTest {
|
||||
GHIssue issue = builder.create();
|
||||
|
||||
// Generate some events.
|
||||
issue.addLabels("test-label");
|
||||
issue.setLabels("test-label");
|
||||
|
||||
// Test that the events are present.
|
||||
List<GHIssueEvent> list = issue.listEvents().toList();
|
||||
|
||||
@@ -79,9 +79,19 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
|
||||
String key = "mit";
|
||||
GHLicense license = gitHub.getLicense(key);
|
||||
assertNotNull(license);
|
||||
assertTrue("The name is correct", license.getName().equals("MIT License"));
|
||||
assertTrue("The HTML URL is correct",
|
||||
license.getHtmlUrl().equals(new URL("http://choosealicense.com/licenses/mit/")));
|
||||
assertThat("The name is correct", license.getName(), equalTo("MIT License"));
|
||||
assertThat("The HTML URL is correct",
|
||||
license.getHtmlUrl(),
|
||||
equalTo(new URL("http://choosealicense.com/licenses/mit/")));
|
||||
assertThat(license.getBody(), startsWith("MIT License\n" + "\n" + "Copyright (c) [year] [fullname]\n\n"));
|
||||
assertThat(license.getForbidden().size(), equalTo(0));
|
||||
assertThat(license.getPermitted().size(), equalTo(0));
|
||||
assertThat(license.getImplementation(),
|
||||
equalTo("Create a text file (typically named LICENSE or LICENSE.txt) in the root of your source code and copy the text of the license into the file. Replace [year] with the current year and [fullname] with the name (or names) of the copyright holders."));
|
||||
assertThat(license.getCategory(), nullValue());
|
||||
assertThat(license.isFeatured(), equalTo(true));
|
||||
assertThat(license.equals(null), equalTo(false));
|
||||
assertThat(license.equals(gitHub.getLicense(key)), equalTo(true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,11 +36,12 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
|
||||
cleanupRepository(GITHUB_API_TEST_ORG + '/' + GITHUB_API_TEST);
|
||||
|
||||
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
|
||||
GHRepository repository = org.createRepository(GITHUB_API_TEST,
|
||||
"a test repository used to test kohsuke's github-api",
|
||||
"http://github-api.kohsuke.org/",
|
||||
"Core Developers",
|
||||
true);
|
||||
GHRepository repository = org.createRepository(GITHUB_API_TEST)
|
||||
.description("a test repository used to test kohsuke's github-api")
|
||||
.homepage("http://github-api.kohsuke.org/")
|
||||
.team(org.getTeamByName("Core Developers"))
|
||||
.private_(false)
|
||||
.create();
|
||||
Assert.assertNotNull(repository);
|
||||
}
|
||||
|
||||
@@ -72,7 +73,7 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
|
||||
.homepage("http://github-api.kohsuke.org/")
|
||||
.team(team)
|
||||
.autoInit(true)
|
||||
.templateRepository(true)
|
||||
.isTemplate(true)
|
||||
.create();
|
||||
Assert.assertNotNull(repository);
|
||||
assertThat(mockGitHub.getRequestCount(), equalTo(requestCount + 1));
|
||||
@@ -136,7 +137,7 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
|
||||
public void testListMembersWithFilter() throws IOException {
|
||||
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
|
||||
|
||||
List<GHUser> admins = org.listMembersWithFilter("all").asList();
|
||||
List<GHUser> admins = org.listMembersWithFilter("all").toList();
|
||||
|
||||
assertNotNull(admins);
|
||||
assertTrue(admins.size() >= 12); // In case more are added in the future
|
||||
@@ -158,7 +159,7 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
|
||||
public void testListMembersWithRole() throws IOException {
|
||||
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
|
||||
|
||||
List<GHUser> admins = org.listMembersWithRole("admin").asList();
|
||||
List<GHUser> admins = org.listMembersWithRole("admin").toList();
|
||||
|
||||
assertNotNull(admins);
|
||||
assertTrue(admins.size() >= 12); // In case more are added in the future
|
||||
|
||||
21
src/test/java/org/kohsuke/github/GHPullRequestMockTest.java
Normal file
21
src/test/java/org/kohsuke/github/GHPullRequestMockTest.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class GHPullRequestMockTest {
|
||||
|
||||
@Test
|
||||
public void shouldMockGHPullRequest() throws IOException {
|
||||
GHPullRequest pullRequest = mock(GHPullRequest.class);
|
||||
when(pullRequest.isDraft()).thenReturn(true);
|
||||
|
||||
assertTrue("Mock should return true", pullRequest.isDraft());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,12 +5,18 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasProperty;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
@@ -112,28 +118,52 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
|
||||
public void pullRequestReviewComments() throws Exception {
|
||||
String name = "pullRequestReviewComments";
|
||||
GHPullRequest p = getRepository().createPullRequest(name, "test/stable", "master", "## test");
|
||||
// System.out.println(p.getUrl());
|
||||
assertTrue(p.listReviewComments().toList().isEmpty());
|
||||
p.createReviewComment("Sample review comment", p.getHead().getSha(), "README.md", 1);
|
||||
List<GHPullRequestReviewComment> comments = p.listReviewComments().toList();
|
||||
assertEquals(1, comments.size());
|
||||
GHPullRequestReviewComment comment = comments.get(0);
|
||||
assertEquals("Sample review comment", comment.getBody());
|
||||
try {
|
||||
// System.out.println(p.getUrl());
|
||||
assertTrue(p.listReviewComments().toList().isEmpty());
|
||||
p.createReviewComment("Sample review comment", p.getHead().getSha(), "README.md", 1);
|
||||
List<GHPullRequestReviewComment> comments = p.listReviewComments().toList();
|
||||
assertEquals(1, comments.size());
|
||||
GHPullRequestReviewComment comment = comments.get(0);
|
||||
assertEquals("Sample review comment", comment.getBody());
|
||||
assertThat(comment.getInReplyToId(), equalTo(-1L));
|
||||
assertThat(comment.getPath(), equalTo("README.md"));
|
||||
assertThat(comment.getPosition(), equalTo(1));
|
||||
assertThat(comment.getUser(), notNullValue());
|
||||
// Assert htmlUrl is not null
|
||||
assertThat(comment.getHtmlUrl(), notNullValue());
|
||||
assertThat(comment.getHtmlUrl().toString(),
|
||||
containsString("hub4j-test-org/github-api/pull/" + p.getNumber()));
|
||||
|
||||
// Assert htmlUrl is not null
|
||||
assertNotNull(comment.getHtmlUrl());
|
||||
assertEquals(new URL("https://github.com/hub4j-test-org/github-api/pull/266#discussion_r321995146"),
|
||||
comment.getHtmlUrl());
|
||||
List<GHReaction> reactions = comment.listReactions().toList();
|
||||
assertThat(reactions.size(), equalTo(0));
|
||||
|
||||
comment.update("Updated review comment");
|
||||
comments = p.listReviewComments().toList();
|
||||
assertEquals(1, comments.size());
|
||||
comment = comments.get(0);
|
||||
assertEquals("Updated review comment", comment.getBody());
|
||||
GHReaction reaction = comment.createReaction(ReactionContent.CONFUSED);
|
||||
assertThat(reaction.getContent(), equalTo(ReactionContent.CONFUSED));
|
||||
|
||||
comment.delete();
|
||||
comments = p.listReviewComments().toList();
|
||||
assertTrue(comments.isEmpty());
|
||||
reactions = comment.listReactions().toList();
|
||||
assertThat(reactions.size(), equalTo(1));
|
||||
|
||||
GHPullRequestReviewComment reply = comment.reply("This is a reply.");
|
||||
assertThat(reply.getInReplyToId(), equalTo(comment.getId()));
|
||||
comments = p.listReviewComments().toList();
|
||||
|
||||
assertEquals(2, comments.size());
|
||||
|
||||
comment.update("Updated review comment");
|
||||
comments = p.listReviewComments().toList();
|
||||
comment = comments.get(0);
|
||||
assertEquals("Updated review comment", comment.getBody());
|
||||
|
||||
comment.delete();
|
||||
comments = p.listReviewComments().toList();
|
||||
// Reply is still present after delete of original comment, but no longer has replyToId
|
||||
assertThat(comments.size(), equalTo(1));
|
||||
assertThat(comments.get(0).getId(), equalTo(reply.getId()));
|
||||
assertThat(comments.get(0).getInReplyToId(), equalTo(-1L));
|
||||
} finally {
|
||||
p.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -395,7 +425,93 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
Collection<GHLabel> labels = getRepository().getPullRequest(p.getNumber()).getLabels();
|
||||
assertEquals(1, labels.size());
|
||||
assertEquals(label, labels.iterator().next().getName());
|
||||
GHLabel savedLabel = labels.iterator().next();
|
||||
assertEquals(label, savedLabel.getName());
|
||||
assertNotNull(savedLabel.getId());
|
||||
assertNotNull(savedLabel.getNodeId());
|
||||
assertFalse(savedLabel.isDefault());
|
||||
}
|
||||
|
||||
@Test
|
||||
// Requires push access to the test repo to pass
|
||||
public void addLabels() throws Exception {
|
||||
GHPullRequest p = getRepository().createPullRequest("addLabels", "test/stable", "master", "## test");
|
||||
String addedLabel1 = "addLabels_label_name_1";
|
||||
String addedLabel2 = "addLabels_label_name_2";
|
||||
String addedLabel3 = "addLabels_label_name_3";
|
||||
|
||||
p.addLabels(addedLabel1);
|
||||
|
||||
int requestCount = mockGitHub.getRequestCount();
|
||||
p.addLabels(addedLabel2, addedLabel3);
|
||||
// multiple labels can be added with one api call
|
||||
assertThat(mockGitHub.getRequestCount(), equalTo(requestCount + 1));
|
||||
|
||||
Collection<GHLabel> labels = getRepository().getPullRequest(p.getNumber()).getLabels();
|
||||
assertEquals(3, labels.size());
|
||||
assertThat(labels,
|
||||
containsInAnyOrder(hasProperty("name", equalTo(addedLabel1)),
|
||||
hasProperty("name", equalTo(addedLabel2)),
|
||||
hasProperty("name", equalTo(addedLabel3))));
|
||||
|
||||
// Adding a label which is already present does not throw an error
|
||||
p.addLabels(addedLabel1);
|
||||
}
|
||||
|
||||
@Test
|
||||
// Requires push access to the test repo to pass
|
||||
public void addLabelsConcurrencyIssue() throws Exception {
|
||||
String addedLabel1 = "addLabelsConcurrencyIssue_label_name_1";
|
||||
String addedLabel2 = "addLabelsConcurrencyIssue_label_name_2";
|
||||
|
||||
GHPullRequest p1 = getRepository()
|
||||
.createPullRequest("addLabelsConcurrencyIssue", "test/stable", "master", "## test");
|
||||
p1.getLabels();
|
||||
|
||||
GHPullRequest p2 = getRepository().getPullRequest(p1.getNumber());
|
||||
p2.addLabels(addedLabel2);
|
||||
|
||||
p1.addLabels(addedLabel1);
|
||||
|
||||
Collection<GHLabel> labels = getRepository().getPullRequest(p1.getNumber()).getLabels();
|
||||
assertEquals(2, labels.size());
|
||||
assertThat(labels,
|
||||
containsInAnyOrder(hasProperty("name", equalTo(addedLabel1)),
|
||||
hasProperty("name", equalTo(addedLabel2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
// Requires push access to the test repo to pass
|
||||
public void removeLabels() throws Exception {
|
||||
GHPullRequest p = getRepository().createPullRequest("removeLabels", "test/stable", "master", "## test");
|
||||
String label1 = "removeLabels_label_name_1";
|
||||
String label2 = "removeLabels_label_name_2";
|
||||
String label3 = "removeLabels_label_name_3";
|
||||
p.setLabels(label1, label2, label3);
|
||||
|
||||
Collection<GHLabel> labels = getRepository().getPullRequest(p.getNumber()).getLabels();
|
||||
assertEquals(3, labels.size());
|
||||
|
||||
int requestCount = mockGitHub.getRequestCount();
|
||||
p.removeLabels(label2, label3);
|
||||
// each label deleted is a separate api call
|
||||
assertThat(mockGitHub.getRequestCount(), equalTo(requestCount + 2));
|
||||
|
||||
labels = getRepository().getPullRequest(p.getNumber()).getLabels();
|
||||
assertEquals(1, labels.size());
|
||||
assertEquals(label1, labels.iterator().next().getName());
|
||||
|
||||
// Removing some labels that are not present does not throw
|
||||
// This is consistent with earlier behavior and with addLabels()
|
||||
p.removeLabels(label3);
|
||||
|
||||
// Calling removeLabel() on label that is not present will throw
|
||||
try {
|
||||
p.removeLabel(label3);
|
||||
fail("Expected GHFileNotFoundException");
|
||||
} catch (GHFileNotFoundException e) {
|
||||
assertThat(e.getMessage(), containsString("Label does not exist"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -412,15 +528,15 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
|
||||
public void getUserTest() throws IOException {
|
||||
GHPullRequest p = getRepository().createPullRequest("getUserTest", "test/stable", "master", "## test");
|
||||
GHPullRequest prSingle = getRepository().getPullRequest(p.getNumber());
|
||||
assertNotNull(prSingle.getUser().root);
|
||||
assertNotNull(prSingle.getUser().getRoot());
|
||||
prSingle.getMergeable();
|
||||
assertNotNull(prSingle.getUser().root);
|
||||
assertNotNull(prSingle.getUser().getRoot());
|
||||
|
||||
PagedIterable<GHPullRequest> ghPullRequests = getRepository().listPullRequests(GHIssueState.OPEN);
|
||||
for (GHPullRequest pr : ghPullRequests) {
|
||||
assertNotNull(pr.getUser().root);
|
||||
assertNotNull(pr.getUser().getRoot());
|
||||
pr.getMergeable();
|
||||
assertNotNull(pr.getUser().root);
|
||||
assertNotNull(pr.getUser().getRoot());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -312,9 +312,6 @@ public class GHRateLimitTest extends AbstractGitHubWireMockTest {
|
||||
// Give this a moment
|
||||
Thread.sleep(1500);
|
||||
|
||||
// lastRateLimit the same as rateLimit
|
||||
assertThat(gitHub.lastRateLimit(), sameInstance(rateLimit));
|
||||
|
||||
// ratelimit() tries not to make additional requests, uses queried rate limit since header not available
|
||||
Thread.sleep(1500);
|
||||
assertThat(gitHub.rateLimit(), sameInstance(rateLimit));
|
||||
@@ -490,9 +487,6 @@ public class GHRateLimitTest extends AbstractGitHubWireMockTest {
|
||||
assertThat("rateLimit() selects header instance when not expired, does not ask server",
|
||||
gitHub.rateLimit(),
|
||||
sameInstance(headerRateLimit));
|
||||
assertThat("lastRateLimit() always selects header instance, does not ask server",
|
||||
gitHub.lastRateLimit(),
|
||||
sameInstance(headerRateLimit));
|
||||
|
||||
assertThat(mockGitHub.getRequestCount(), equalTo(1));
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
|
||||
for (GHRepositoryStatistics.ContributorStats statsForAuthor : list) {
|
||||
if (authorLogin.equals(statsForAuthor.getAuthor().getLogin())) {
|
||||
assertEquals(715, statsForAuthor.getTotal());
|
||||
assertEquals("kohsuke made 715 contributions over 494 weeks", statsForAuthor.toString());
|
||||
|
||||
List<GHRepositoryStatistics.ContributorStats.Week> weeks = statsForAuthor.getWeeks();
|
||||
assertEquals(494, weeks.size());
|
||||
@@ -46,6 +47,8 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
|
||||
assertEquals(63, week.getNumberOfAdditions());
|
||||
assertEquals(56, week.getNumberOfDeletions());
|
||||
assertEquals(5, week.getNumberOfCommits());
|
||||
assertEquals("Week starting 1541289600 - Additions: 63, Deletions: 56, Commits: 5",
|
||||
week.toString());
|
||||
} catch (NoSuchElementException e) {
|
||||
fail("Did not find week 1546128000");
|
||||
}
|
||||
@@ -131,6 +134,7 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
|
||||
if (item.getWeekTimestamp() == 1535241600) {
|
||||
assertEquals(185, item.getAdditions());
|
||||
assertEquals(-243, item.getDeletions());
|
||||
assertEquals("Week starting 1535241600 has 185 additions and 243 deletions", item.toString());
|
||||
foundWeek = true;
|
||||
break;
|
||||
}
|
||||
@@ -196,6 +200,7 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
|
||||
// TODO: Make an easier access method. Perhaps wrap in an
|
||||
// object and have a method such as GetCommits(1, 16).
|
||||
assertEquals(16, item.getNumberOfCommits());
|
||||
assertEquals("Day 2 Hour 10: 16 commits", item.toString());
|
||||
hourFound = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3,11 +3,15 @@ package org.kohsuke.github;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
import org.kohsuke.github.GHCheckRun.Conclusion;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -28,6 +32,20 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
return gitHub.getOrganization("hub4j-test-org").getRepository("github-api");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZipball() throws IOException {
|
||||
getTempRepository().readZip((InputStream inputstream) -> {
|
||||
return new ByteArrayInputStream(IOUtils.toByteArray(inputstream));
|
||||
}, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTarball() throws IOException {
|
||||
getTempRepository().readTar((InputStream inputstream) -> {
|
||||
return new ByteArrayInputStream(IOUtils.toByteArray(inputstream));
|
||||
}, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters() throws IOException {
|
||||
GHRepository r = getTempRepository();
|
||||
@@ -110,6 +128,19 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
assertEquals(UNKNOWN_SIGNATURE_TYPE, verification.getReason());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listStargazers() throws IOException {
|
||||
GHRepository repository = getRepository();
|
||||
assertThat(repository.listStargazers2().toList(), empty());
|
||||
|
||||
repository = gitHub.getOrganization("hub4j").getRepository("github-api");
|
||||
Iterable<GHStargazer> stargazers = repository.listStargazers2();
|
||||
GHStargazer stargazer = stargazers.iterator().next();
|
||||
assertThat(stargazer.getStarredAt(), equalTo(new Date(1271650383000L)));
|
||||
assertThat(stargazer.getUser().getLogin(), equalTo("nielswind"));
|
||||
assertThat(stargazer.getRepository(), sameInstance(repository));
|
||||
}
|
||||
|
||||
// Issue #607
|
||||
@Test
|
||||
public void getBranchNonExistentBut200Status() throws Exception {
|
||||
@@ -135,11 +166,20 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
public void subscription() throws Exception {
|
||||
GHRepository r = getRepository();
|
||||
assertNull(r.getSubscription());
|
||||
|
||||
GHSubscription s = r.subscribe(true, false);
|
||||
assertEquals(s.getRepository(), r);
|
||||
try {
|
||||
|
||||
s.delete();
|
||||
assertEquals(s.getRepository(), r);
|
||||
assertThat(s.isIgnored(), equalTo(false));
|
||||
assertThat(s.isSubscribed(), equalTo(true));
|
||||
assertThat(s.getRepositoryUrl().toString(), containsString("/repos/hub4j-test-org/github-api"));
|
||||
assertThat(s.getUrl().toString(), containsString("/repos/hub4j-test-org/github-api/subscription"));
|
||||
|
||||
assertThat(s.getReason(), nullValue());
|
||||
assertThat(s.getCreatedAt(), equalTo(new Date(1611377286000L)));
|
||||
} finally {
|
||||
s.delete();
|
||||
}
|
||||
|
||||
assertNull(r.getSubscription());
|
||||
}
|
||||
@@ -641,17 +681,6 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
assertThat(e, instanceOf(GHFileNotFoundException.class));
|
||||
assertThat(e.getMessage(), containsString("/repos/hub4j-test-org/temp-listRefsEmptyTags/git/refs/tags"));
|
||||
}
|
||||
|
||||
try {
|
||||
GHRepository repo = getTempRepository();
|
||||
repo.listRefs("tags").asList();
|
||||
fail();
|
||||
} catch (Exception e) {
|
||||
assertThat(e, instanceOf(GHException.class));
|
||||
assertThat(e.getMessage(), containsString("Failed to retrieve "));
|
||||
assertThat(e.getMessage(), containsString("/repos/hub4j-test-org/temp-listRefsEmptyTags/git/refs/tags"));
|
||||
assertThat(e.getCause(), instanceOf(GHFileNotFoundException.class));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -715,7 +744,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
// Check if the checkruns are all succeeded and if we got all of them
|
||||
int checkRunsCount = 0;
|
||||
for (GHCheckRun checkRun : checkRuns) {
|
||||
assertThat(checkRun.getConclusion(), equalTo("success"));
|
||||
assertThat(checkRun.getConclusion(), equalTo(Conclusion.SUCCESS));
|
||||
checkRunsCount++;
|
||||
}
|
||||
assertThat(checkRunsCount, equalTo(expectedCount));
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@@ -49,6 +50,10 @@ public class GHTagTest extends AbstractGitHubWireMockTest {
|
||||
assertEquals(commitSha, tag.getObject().getSha());
|
||||
assertFalse(tag.getVerification().isVerified());
|
||||
assertEquals(tag.getVerification().getReason(), GHVerification.Reason.UNSIGNED);
|
||||
assertThat(tag.getUrl(),
|
||||
containsString("/repos/hub4j-test-org/github-api/git/tags/e7aa6d4afbaa48669f0bbe11ca3c4d787b2b153c"));
|
||||
assertThat(tag.getOwner().getId(), equalTo(repo.getId()));
|
||||
assertThat(tag.getTagger().getEmail(), equalTo("martin.vanzijl@gmail.com"));
|
||||
|
||||
// Make a reference to the newly created tag.
|
||||
GHRef ref = repo.createRef("refs/tags/" + tagName, tag.getSha());
|
||||
|
||||
@@ -41,7 +41,7 @@ public class GHTeamTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
|
||||
|
||||
List<GHUser> admins = team.listMembers("admin").asList();
|
||||
List<GHUser> admins = team.listMembers("admin").toList();
|
||||
|
||||
assertNotNull(admins);
|
||||
assertThat("One admin in dummy team", admins.size() == 1);
|
||||
@@ -55,7 +55,7 @@ public class GHTeamTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
|
||||
|
||||
List<GHUser> justMembers = team.listMembers("member").asList();
|
||||
List<GHUser> justMembers = team.listMembers("member").toList();
|
||||
|
||||
assertThat("No regular members in team", justMembers.isEmpty());
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class GHTreeBuilderTest extends AbstractGitHubWireMockTest {
|
||||
@@ -87,22 +89,30 @@ public class GHTreeBuilderTest extends AbstractGitHubWireMockTest {
|
||||
treeBuilder.add(PATH_DATA1, CONTENT_DATA1, false);
|
||||
treeBuilder.add(PATH_DATA2, CONTENT_DATA2, false);
|
||||
|
||||
updateTree();
|
||||
GHCommit commit = updateTree();
|
||||
|
||||
assertEquals(CONTENT_SCRIPT.length(), getFileSize(PATH_SCRIPT));
|
||||
assertEquals(CONTENT_README.length(), getFileSize(PATH_README));
|
||||
assertEquals(CONTENT_DATA1.length, getFileSize(PATH_DATA1));
|
||||
assertEquals(CONTENT_DATA2.length, getFileSize(PATH_DATA2));
|
||||
|
||||
assertThat(commit.getCommitShortInfo().getAuthor().getEmail(), equalTo("author@author.com"));
|
||||
assertThat(commit.getCommitShortInfo().getCommitter().getEmail(), equalTo("committer@committer.com"));
|
||||
|
||||
}
|
||||
|
||||
private void updateTree() throws IOException {
|
||||
private GHCommit updateTree() throws IOException {
|
||||
String treeSha = treeBuilder.create().getSha();
|
||||
String commitSha = new GHCommitBuilder(repo).message("Add files")
|
||||
GHCommit commit = new GHCommitBuilder(repo).message("Add files")
|
||||
.tree(treeSha)
|
||||
.author("author", "author@author.com", new Date(1611433225969L))
|
||||
.committer("committer", "committer@committer.com", new Date(1611433225968L))
|
||||
.parent(masterRef.getObject().getSha())
|
||||
.create()
|
||||
.getSHA1();
|
||||
.create();
|
||||
|
||||
String commitSha = commit.getSHA1();
|
||||
masterRef.updateTo(commitSha);
|
||||
return commit;
|
||||
}
|
||||
|
||||
private long getFileSize(String path) throws IOException {
|
||||
|
||||
@@ -39,14 +39,27 @@ public class GHUserTest extends AbstractGitHubWireMockTest {
|
||||
}
|
||||
});
|
||||
assertEquals(1066173, ghKeys.get(0).getId());
|
||||
assertThat(ghKeys.get(0).getTitle(), nullValue());
|
||||
assertThat(ghKeys.get(0).getUrl(), nullValue());
|
||||
assertThat(ghKeys.get(0).isVerified(), equalTo(false));
|
||||
assertThat(ghKeys.get(0).toString(),
|
||||
containsString(
|
||||
"title=<null>,id=1066173,key=ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAueiy12T5bvFhsc9YjfLc3aVIxgySd3gDxQWy/bletIoZL8omKmzocBYJ7F58U1asoyfWsy2ToTOY8jJp1eToXmbD6L5+xvHba0A7djYh9aQRrFam7doKQ0zp0ZSUF6+R1v0OM4nnWqK4n2ECIYd+Bdzrp+xA5+XlW3ZSNzlnW2BeWznzmgRMcp6wI+zQ9GMHWviR1cxpml5Z6wrxTZ0aX91btvnNPqoOGva976B6e6403FOEkkIFTk6CC1TFKwc/VjbqxYBg4kU0JhiTP+iEZibcQrYjWdYUgAotYbFVe5/DneHMLNsMPdeihba4PUwt62rXyNegenuCRmCntLcaFQ=="));
|
||||
|
||||
assertEquals(
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAueiy12T5bvFhsc9YjfLc3aVIxgySd3gDxQWy/bletIoZL8omKmzocBYJ7F58U1asoyfWsy2ToTOY8jJp1eToXmbD6L5+xvHba0A7djYh9aQRrFam7doKQ0zp0ZSUF6+R1v0OM4nnWqK4n2ECIYd+Bdzrp+xA5+XlW3ZSNzlnW2BeWznzmgRMcp6wI+zQ9GMHWviR1cxpml5Z6wrxTZ0aX91btvnNPqoOGva976B6e6403FOEkkIFTk6CC1TFKwc/VjbqxYBg4kU0JhiTP+iEZibcQrYjWdYUgAotYbFVe5/DneHMLNsMPdeihba4PUwt62rXyNegenuCRmCntLcaFQ==",
|
||||
ghKeys.get(0).getKey());
|
||||
assertEquals(28136459, ghKeys.get(1).getId());
|
||||
assertThat(ghKeys.get(1).getTitle(), nullValue());
|
||||
assertThat(ghKeys.get(1).getUrl(), nullValue());
|
||||
assertThat(ghKeys.get(1).isVerified(), equalTo(false));
|
||||
assertEquals(
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTU0s5OKCC6VpKZGL9NJD4mNLY0AtujkVB1JkkuQ4OkMi2YGUHJtGhTbTwEVhNxpm0x2dM5KSzse6MLDYuGBW0qkE/VVuD9+9I73hbq461KqP0+WlupNh+Qc86kbiLBDv64+vWc+50mp1dbINpoM5xvaPYxgjnemydPv7vu5bhCHBugW7aN8VcLgfFgcp8vZCEanMtd3hIRjRU8v8Skk233ZGu1bXkG8iIOBQPabvEtZ0VDMg9pT3Q1R6lnnKqfCwHXd6zP6uAtejFSxvKRGKpu3OLGQMHwk7NlImVuhkVdaEFBq7pQtpOaGuP2eLKcN1wy5jsTYE+ZB6pvHCi2ecb",
|
||||
ghKeys.get(1).getKey());
|
||||
assertEquals(31452581, ghKeys.get(2).getId());
|
||||
assertThat(ghKeys.get(2).getTitle(), nullValue());
|
||||
assertThat(ghKeys.get(2).getUrl(), nullValue());
|
||||
assertThat(ghKeys.get(2).isVerified(), equalTo(false));
|
||||
assertEquals(
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC3JhH2FZBDmHLjXTcBoV6tdcYKmsQ7sgu8k1RsUhwxGsXm65+Cuas6GcMVoA1DncKfJGQkulHDFiTxIROIBmedh9/otHWBlZ4HqYZ4MQ1A8W5quULkXwX/kF+UdRBUxFvjigibEbuHB+LARVxRRzFlPnTSE9rAfAv8OOEsb3lNUGT/IGhN8w1vwe8GclB90tgqN1RBDgrVqwLFwn5AfrW9kUIa2f2oT4RjYu1OrhKhVIIzfHADo85aD+s8wEhqwI96BCJG3qTWrypoHwBUoj1O6Ak5CGc1iKz9o8XyTMjudRt2ddCjfOtxsuwSlTbVtQXJGIpgKviX1sgh4pPvGh7BVAFP+mdAK4F+mEugDnuj47GO/K5KGGDRCL56kh9+h28l4q/+fZvp7DhtmSN2EzrVAdQFskF8yY/6Xit/aAvjeKm03DcjbylSXbG26EJefaLHlwYFq2mUFRMak25wuuCZS71GF3RC3Sl/bMoxBKRYkyfYtGafeaYTFNGn8Dbd+hfVUCz31ebI8cvmlQR5b5AbCre3T7HTVgw8FKbAxWRf1Fio56PnqHsj+sT1KVj255Zo1F8iD9GrgERSVAlkh5bY/CKszQ8ZSd01c9Qp2a47/gR7XAAbxhzGHP+cSOlrqDlJ24fbPtcpVsM0llqKUcxpmoOBFNboRmE1QqnSmAf9ww==",
|
||||
ghKeys.get(2).getKey());
|
||||
@@ -109,5 +122,11 @@ public class GHUserTest extends AbstractGitHubWireMockTest {
|
||||
assertThat(u.getBio(), equalTo("I like to program things and I hope to program something cool one day :D"));
|
||||
assertTrue(u.isHireable());
|
||||
assertNotNull(u.getTwitterUsername());
|
||||
assertThat(u.getBlog(), equalTo("https://chew.pw"));
|
||||
assertThat(u.getCompany(), equalTo("@Memerator"));
|
||||
assertThat(u.getFollowersCount(), equalTo(29));
|
||||
assertThat(u.getFollowingCount(), equalTo(3));
|
||||
assertThat(u.getPublicGistCount(), equalTo(4));
|
||||
assertThat(u.getPublicRepoCount(), equalTo(96));
|
||||
}
|
||||
}
|
||||
|
||||
233
src/test/java/org/kohsuke/github/GHWorkflowRunTest.java
Normal file
233
src/test/java/org/kohsuke/github/GHWorkflowRunTest.java
Normal file
@@ -0,0 +1,233 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.kohsuke.github.GHWorkflowRun.Conclusion;
|
||||
import org.kohsuke.github.GHWorkflowRun.Status;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
private static final String REPO_NAME = "hub4j-test-org/GHWorkflowRunTest";
|
||||
private static final String MAIN_BRANCH = "main";
|
||||
private static final String SECOND_BRANCH = "second-branch";
|
||||
|
||||
private static final String FAST_WORKFLOW_PATH = "fast-workflow.yml";
|
||||
private static final String FAST_WORKFLOW_NAME = "Fast workflow";
|
||||
|
||||
private static final String SLOW_WORKFLOW_PATH = "slow-workflow.yml";
|
||||
private static final String SLOW_WORKFLOW_NAME = "Slow workflow";
|
||||
|
||||
private GHRepository repo;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
repo = gitHub.getRepository(REPO_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManualRunAndBasicInformation() throws IOException {
|
||||
GHWorkflow workflow = repo.getWorkflow(FAST_WORKFLOW_PATH);
|
||||
|
||||
long latestPreexistingWorkflowRunId = getLatestPreexistingWorkflowRunId();
|
||||
|
||||
workflow.dispatch(MAIN_BRANCH);
|
||||
|
||||
await((nonRecordingRepo) -> getWorkflowRun(nonRecordingRepo,
|
||||
FAST_WORKFLOW_NAME,
|
||||
MAIN_BRANCH,
|
||||
Status.COMPLETED,
|
||||
latestPreexistingWorkflowRunId).isPresent());
|
||||
|
||||
GHWorkflowRun workflowRun = getWorkflowRun(FAST_WORKFLOW_NAME,
|
||||
MAIN_BRANCH,
|
||||
Status.COMPLETED,
|
||||
latestPreexistingWorkflowRunId).orElseThrow(
|
||||
() -> new IllegalStateException("We must have a valid workflow run starting from here"));
|
||||
|
||||
assertEquals(workflow.getId(), workflowRun.getWorkflowId());
|
||||
assertTrue(workflowRun.getUrl().getPath().contains("/actions/runs/"));
|
||||
assertTrue(workflowRun.getHtmlUrl().getPath().contains("/actions/runs/"));
|
||||
assertTrue(workflowRun.getJobsUrl().getPath().endsWith("/jobs"));
|
||||
assertTrue(workflowRun.getLogsUrl().getPath().endsWith("/logs"));
|
||||
assertTrue(workflowRun.getCheckSuiteUrl().getPath().contains("/check-suites/"));
|
||||
assertTrue(workflowRun.getArtifactsUrl().getPath().endsWith("/artifacts"));
|
||||
assertTrue(workflowRun.getCancelUrl().getPath().endsWith("/cancel"));
|
||||
assertTrue(workflowRun.getRerunUrl().getPath().endsWith("/rerun"));
|
||||
assertTrue(workflowRun.getWorkflowUrl().getPath().contains("/actions/workflows/"));
|
||||
assertEquals(MAIN_BRANCH, workflowRun.getHeadBranch());
|
||||
assertNotNull(workflowRun.getHeadCommit().getId());
|
||||
assertNotNull(workflowRun.getHeadCommit().getTreeId());
|
||||
assertNotNull(workflowRun.getHeadCommit().getMessage());
|
||||
assertNotNull(workflowRun.getHeadCommit().getTimestamp());
|
||||
assertNotNull(workflowRun.getHeadCommit().getAuthor().getEmail());
|
||||
assertNotNull(workflowRun.getHeadCommit().getCommitter().getEmail());
|
||||
assertEquals(GHEvent.WORKFLOW_DISPATCH, workflowRun.getEvent());
|
||||
assertEquals(Status.COMPLETED, workflowRun.getStatus());
|
||||
assertEquals(Conclusion.SUCCESS, workflowRun.getConclusion());
|
||||
assertNotNull(workflowRun.getHeadSha());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCancelAndRerun() throws IOException {
|
||||
GHWorkflow workflow = repo.getWorkflow(SLOW_WORKFLOW_PATH);
|
||||
|
||||
long latestPreexistingWorkflowRunId = getLatestPreexistingWorkflowRunId();
|
||||
|
||||
workflow.dispatch(MAIN_BRANCH);
|
||||
|
||||
// now that we have triggered the workflow run, we will wait until it's in progress and then cancel it
|
||||
await((nonRecordingRepo) -> getWorkflowRun(nonRecordingRepo,
|
||||
SLOW_WORKFLOW_NAME,
|
||||
MAIN_BRANCH,
|
||||
Status.IN_PROGRESS,
|
||||
latestPreexistingWorkflowRunId).isPresent());
|
||||
|
||||
GHWorkflowRun workflowRun = getWorkflowRun(SLOW_WORKFLOW_NAME,
|
||||
MAIN_BRANCH,
|
||||
Status.IN_PROGRESS,
|
||||
latestPreexistingWorkflowRunId).orElseThrow(
|
||||
() -> new IllegalStateException("We must have a valid workflow run starting from here"));
|
||||
|
||||
assertNotNull(workflowRun.getId());
|
||||
|
||||
workflowRun.cancel();
|
||||
long cancelledWorkflowRunId = workflowRun.getId();
|
||||
|
||||
// let's wait until it's completed
|
||||
await((nonRecordingRepo) -> getWorkflowRunStatus(nonRecordingRepo, cancelledWorkflowRunId) == Status.COMPLETED);
|
||||
|
||||
// let's check that it has been properly cancelled
|
||||
workflowRun = repo.getWorkflowRun(cancelledWorkflowRunId);
|
||||
assertEquals(Conclusion.CANCELLED, workflowRun.getConclusion());
|
||||
|
||||
// now let's rerun it
|
||||
workflowRun.rerun();
|
||||
|
||||
// let's check that it has been rerun
|
||||
await((nonRecordingRepo) -> getWorkflowRunStatus(nonRecordingRepo,
|
||||
cancelledWorkflowRunId) == Status.IN_PROGRESS);
|
||||
|
||||
// cancel it again
|
||||
workflowRun.cancel();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelete() throws IOException {
|
||||
GHWorkflow workflow = repo.getWorkflow(FAST_WORKFLOW_PATH);
|
||||
|
||||
long latestPreexistingWorkflowRunId = getLatestPreexistingWorkflowRunId();
|
||||
|
||||
workflow.dispatch(MAIN_BRANCH);
|
||||
|
||||
await((nonRecordingRepo) -> getWorkflowRun(nonRecordingRepo,
|
||||
FAST_WORKFLOW_NAME,
|
||||
MAIN_BRANCH,
|
||||
Status.COMPLETED,
|
||||
latestPreexistingWorkflowRunId).isPresent());
|
||||
|
||||
GHWorkflowRun workflowRunToDelete = getWorkflowRun(FAST_WORKFLOW_NAME,
|
||||
MAIN_BRANCH,
|
||||
Status.COMPLETED,
|
||||
latestPreexistingWorkflowRunId).orElseThrow(
|
||||
() -> new IllegalStateException("We must have a valid workflow run starting from here"));
|
||||
|
||||
assertNotNull(workflowRunToDelete.getId());
|
||||
|
||||
workflowRunToDelete.delete();
|
||||
|
||||
try {
|
||||
repo.getWorkflowRun(workflowRunToDelete.getId());
|
||||
Assert.fail("The workflow " + workflowRunToDelete.getId() + " should have been deleted.");
|
||||
} catch (GHFileNotFoundException e) {
|
||||
// success
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchOnBranch() throws IOException {
|
||||
GHWorkflow workflow = repo.getWorkflow(FAST_WORKFLOW_PATH);
|
||||
|
||||
long latestPreexistingWorkflowRunId = getLatestPreexistingWorkflowRunId();
|
||||
|
||||
workflow.dispatch(SECOND_BRANCH);
|
||||
|
||||
await((nonRecordingRepo) -> getWorkflowRun(nonRecordingRepo,
|
||||
FAST_WORKFLOW_NAME,
|
||||
SECOND_BRANCH,
|
||||
Status.COMPLETED,
|
||||
latestPreexistingWorkflowRunId).isPresent());
|
||||
|
||||
GHWorkflowRun workflowRun = getWorkflowRun(FAST_WORKFLOW_NAME,
|
||||
SECOND_BRANCH,
|
||||
Status.COMPLETED,
|
||||
latestPreexistingWorkflowRunId).orElseThrow(
|
||||
() -> new IllegalStateException("We must have a valid workflow run starting from here"));
|
||||
|
||||
assertEquals(workflow.getId(), workflowRun.getWorkflowId());
|
||||
assertEquals(SECOND_BRANCH, workflowRun.getHeadBranch());
|
||||
assertEquals(GHEvent.WORKFLOW_DISPATCH, workflowRun.getEvent());
|
||||
assertEquals(Status.COMPLETED, workflowRun.getStatus());
|
||||
assertEquals(Conclusion.SUCCESS, workflowRun.getConclusion());
|
||||
}
|
||||
|
||||
private void await(Function<GHRepository, Boolean> condition) throws IOException {
|
||||
if (!mockGitHub.isUseProxy()) {
|
||||
return;
|
||||
}
|
||||
|
||||
GHRepository nonRecordingRepo = getGitHubBeforeAfter().getRepository(REPO_NAME);
|
||||
|
||||
Awaitility.await().pollInterval(Duration.ofSeconds(5)).atMost(Duration.ofSeconds(60)).until(() -> {
|
||||
return condition.apply(nonRecordingRepo);
|
||||
});
|
||||
}
|
||||
|
||||
private long getLatestPreexistingWorkflowRunId() {
|
||||
return repo.queryWorkflowRuns().list().withPageSize(1).iterator().next().getId();
|
||||
}
|
||||
|
||||
private static Optional<GHWorkflowRun> getWorkflowRun(GHRepository repository,
|
||||
String workflowName,
|
||||
String branch,
|
||||
Status status,
|
||||
long latestPreexistingWorkflowRunId) {
|
||||
List<GHWorkflowRun> workflowRuns = repository.queryWorkflowRuns()
|
||||
.branch(branch)
|
||||
.status(status)
|
||||
.event(GHEvent.WORKFLOW_DISPATCH)
|
||||
.list()
|
||||
.withPageSize(20)
|
||||
.iterator()
|
||||
.nextPage();
|
||||
|
||||
for (GHWorkflowRun workflowRun : workflowRuns) {
|
||||
if (workflowRun.getName().equals(workflowName) && workflowRun.getId() > latestPreexistingWorkflowRunId) {
|
||||
return Optional.of(workflowRun);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private Optional<GHWorkflowRun> getWorkflowRun(String workflowName,
|
||||
String branch,
|
||||
Status status,
|
||||
long latestPreexistingWorkflowRunId) {
|
||||
return getWorkflowRun(this.repo, workflowName, branch, status, latestPreexistingWorkflowRunId);
|
||||
}
|
||||
|
||||
private static Status getWorkflowRunStatus(GHRepository repository, long workflowRunId) {
|
||||
try {
|
||||
return repository.getWorkflowRun(workflowRunId).getStatus();
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Unable to get workflow run status", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
89
src/test/java/org/kohsuke/github/GHWorkflowTest.java
Normal file
89
src/test/java/org/kohsuke/github/GHWorkflowTest.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.containing;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
|
||||
|
||||
public class GHWorkflowTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
private static String REPO_NAME = "hub4j-test-org/GHWorkflowTest";
|
||||
|
||||
private GHRepository repo;
|
||||
|
||||
@Before
|
||||
@After
|
||||
public void cleanup() throws Exception {
|
||||
if (mockGitHub.isUseProxy()) {
|
||||
repo = getGitHubBeforeAfter().getRepository(REPO_NAME);
|
||||
|
||||
// we need to make sure the workflow is enabled before the tests
|
||||
GHWorkflow workflow = repo.getWorkflow("test-workflow.yml");
|
||||
if (!workflow.getState().equals("active")) {
|
||||
workflow.enable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
repo = gitHub.getRepository(REPO_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicInformation() throws IOException {
|
||||
GHWorkflow workflow = repo.getWorkflow("test-workflow.yml");
|
||||
|
||||
assertEquals("test-workflow", workflow.getName());
|
||||
assertEquals(".github/workflows/test-workflow.yml", workflow.getPath());
|
||||
assertEquals("active", workflow.getState());
|
||||
assertEquals("/repos/hub4j-test-org/GHWorkflowTest/actions/workflows/6817859", workflow.getUrl().getPath());
|
||||
assertEquals("/hub4j-test-org/GHWorkflowTest/blob/main/.github/workflows/test-workflow.yml",
|
||||
workflow.getHtmlUrl().getPath());
|
||||
assertEquals("/hub4j-test-org/GHWorkflowTest/workflows/test-workflow/badge.svg",
|
||||
workflow.getBadgeUrl().getPath());
|
||||
|
||||
GHWorkflow workflowById = repo.getWorkflow(workflow.getId());
|
||||
assertEquals(workflow.getNodeId(), workflowById.getNodeId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableEnable() throws IOException {
|
||||
GHWorkflow workflow = repo.getWorkflow("test-workflow.yml");
|
||||
|
||||
assertEquals("active", workflow.getState());
|
||||
|
||||
workflow.disable();
|
||||
|
||||
workflow = repo.getWorkflow("test-workflow.yml");
|
||||
assertEquals("disabled_manually", workflow.getState());
|
||||
|
||||
workflow.enable();
|
||||
|
||||
workflow = repo.getWorkflow("test-workflow.yml");
|
||||
assertEquals("active", workflow.getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDispatch() throws IOException {
|
||||
GHWorkflow workflow = repo.getWorkflow("test-workflow.yml");
|
||||
|
||||
workflow.dispatch("main");
|
||||
verify(postRequestedFor(
|
||||
urlPathEqualTo("/repos/hub4j-test-org/GHWorkflowTest/actions/workflows/6817859/dispatches")));
|
||||
|
||||
workflow.dispatch("main", Collections.singletonMap("parameter", "value"));
|
||||
verify(postRequestedFor(
|
||||
urlPathEqualTo("/repos/hub4j-test-org/GHWorkflowTest/actions/workflows/6817859/dispatches"))
|
||||
.withRequestBody(containing("inputs"))
|
||||
.withRequestBody(containing("parameter"))
|
||||
.withRequestBody(containing("value")));
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,20 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.junit.Assume;
|
||||
import org.junit.Test;
|
||||
import org.kohsuke.github.authorization.UserAuthorizationProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* Unit test for {@link GitHub}.
|
||||
@@ -53,55 +63,97 @@ public class GitHubConnectionTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
@Test
|
||||
public void testGitHubBuilderFromEnvironment() throws IOException {
|
||||
// we disable this test for JDK 16+ as the current hacks in setupEnvironment() don't work with JDK 16+
|
||||
Assume.assumeThat(Double.valueOf(System.getProperty("java.specification.version")), lessThan(16.0));
|
||||
|
||||
Map<String, String> props = new HashMap<String, String>();
|
||||
|
||||
props.put("login", "bogus");
|
||||
props.put("oauth", "bogus");
|
||||
props.put("password", "bogus");
|
||||
props.put("jwt", "bogus");
|
||||
|
||||
props.put("endpoint", "bogus endpoint url");
|
||||
props.put("oauth", "bogus oauth token string");
|
||||
setupEnvironment(props);
|
||||
|
||||
GitHubBuilder builder = GitHubBuilder.fromEnvironment();
|
||||
|
||||
assertEquals("bogus", builder.user);
|
||||
assertEquals("bogus", builder.oauthToken);
|
||||
assertEquals("bogus", builder.password);
|
||||
assertEquals("bogus", builder.jwtToken);
|
||||
assertThat(builder.endpoint, equalTo("bogus endpoint url"));
|
||||
|
||||
assertThat(builder.authorizationProvider, instanceOf(UserAuthorizationProvider.class));
|
||||
assertThat(builder.authorizationProvider.getEncodedAuthorization(), equalTo("token bogus oauth token string"));
|
||||
assertThat(((UserAuthorizationProvider) builder.authorizationProvider).getLogin(), nullValue());
|
||||
|
||||
props.put("login", "bogus login");
|
||||
setupEnvironment(props);
|
||||
builder = GitHubBuilder.fromEnvironment();
|
||||
|
||||
assertThat(builder.authorizationProvider, instanceOf(UserAuthorizationProvider.class));
|
||||
assertThat(builder.authorizationProvider.getEncodedAuthorization(), equalTo("token bogus oauth token string"));
|
||||
assertThat(((UserAuthorizationProvider) builder.authorizationProvider).getLogin(), equalTo("bogus login"));
|
||||
|
||||
props.put("jwt", "bogus jwt token string");
|
||||
setupEnvironment(props);
|
||||
builder = GitHubBuilder.fromEnvironment();
|
||||
|
||||
assertThat(builder.authorizationProvider, not(instanceOf(UserAuthorizationProvider.class)));
|
||||
assertThat(builder.authorizationProvider.getEncodedAuthorization(), equalTo("Bearer bogus jwt token string"));
|
||||
|
||||
props.put("password", "bogus weak password");
|
||||
setupEnvironment(props);
|
||||
builder = GitHubBuilder.fromEnvironment();
|
||||
|
||||
assertThat(builder.authorizationProvider, instanceOf(UserAuthorizationProvider.class));
|
||||
assertThat(builder.authorizationProvider.getEncodedAuthorization(),
|
||||
equalTo("Basic Ym9ndXMgbG9naW46Ym9ndXMgd2VhayBwYXNzd29yZA=="));
|
||||
assertThat(((UserAuthorizationProvider) builder.authorizationProvider).getLogin(), equalTo("bogus login"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGitHubBuilderFromCustomEnvironment() throws IOException {
|
||||
// we disable this test for JDK 16+ as the current hacks in setupEnvironment() don't work with JDK 16+
|
||||
Assume.assumeThat(Double.valueOf(System.getProperty("java.specification.version")), lessThan(16.0));
|
||||
|
||||
Map<String, String> props = new HashMap<String, String>();
|
||||
|
||||
props.put("customLogin", "bogusLogin");
|
||||
props.put("customOauth", "bogusOauth");
|
||||
props.put("customPassword", "bogusPassword");
|
||||
props.put("customEndpoint", "bogusEndpoint");
|
||||
|
||||
props.put("customEndpoint", "bogus endpoint url");
|
||||
props.put("customOauth", "bogus oauth token string");
|
||||
setupEnvironment(props);
|
||||
|
||||
GitHubBuilder builder = GitHubBuilder
|
||||
.fromEnvironment("customLogin", "customPassword", "customOauth", "customEndpoint");
|
||||
|
||||
assertEquals("bogusLogin", builder.user);
|
||||
assertEquals("bogusOauth", builder.oauthToken);
|
||||
assertEquals("bogusPassword", builder.password);
|
||||
assertEquals("bogusEndpoint", builder.endpoint);
|
||||
assertThat(builder.endpoint, equalTo("bogus endpoint url"));
|
||||
|
||||
assertThat(builder.authorizationProvider, instanceOf(UserAuthorizationProvider.class));
|
||||
assertThat(builder.authorizationProvider.getEncodedAuthorization(), equalTo("token bogus oauth token string"));
|
||||
assertThat(((UserAuthorizationProvider) builder.authorizationProvider).getLogin(), nullValue());
|
||||
|
||||
props.put("customLogin", "bogus login");
|
||||
setupEnvironment(props);
|
||||
builder = GitHubBuilder.fromEnvironment("customLogin", "customPassword", "customOauth", "customEndpoint");
|
||||
|
||||
assertThat(builder.authorizationProvider, instanceOf(UserAuthorizationProvider.class));
|
||||
assertThat(builder.authorizationProvider.getEncodedAuthorization(), equalTo("token bogus oauth token string"));
|
||||
assertThat(((UserAuthorizationProvider) builder.authorizationProvider).getLogin(), equalTo("bogus login"));
|
||||
|
||||
props.put("customPassword", "bogus weak password");
|
||||
setupEnvironment(props);
|
||||
builder = GitHubBuilder.fromEnvironment("customLogin", "customPassword", "customOauth", "customEndpoint");
|
||||
|
||||
assertThat(builder.authorizationProvider, instanceOf(UserAuthorizationProvider.class));
|
||||
assertThat(builder.authorizationProvider.getEncodedAuthorization(),
|
||||
equalTo("Basic Ym9ndXMgbG9naW46Ym9ndXMgd2VhayBwYXNzd29yZA=="));
|
||||
assertThat(((UserAuthorizationProvider) builder.authorizationProvider).getLogin(), equalTo("bogus login"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGithubBuilderWithAppInstallationToken() throws Exception {
|
||||
GitHubBuilder builder = new GitHubBuilder().withAppInstallationToken("bogus");
|
||||
assertEquals("bogus", builder.oauthToken);
|
||||
assertEquals("", builder.user);
|
||||
|
||||
GitHubBuilder builder = new GitHubBuilder().withAppInstallationToken("bogus app token");
|
||||
assertThat(builder.authorizationProvider, instanceOf(UserAuthorizationProvider.class));
|
||||
assertThat(builder.authorizationProvider.getEncodedAuthorization(), equalTo("token bogus app token"));
|
||||
assertThat(((UserAuthorizationProvider) builder.authorizationProvider).getLogin(), equalTo(""));
|
||||
|
||||
// test authorization header is set as in the RFC6749
|
||||
GitHub github = builder.build();
|
||||
// change this to get a request
|
||||
assertEquals("token bogus", github.getClient().encodedAuthorization);
|
||||
assertEquals("token bogus app token", github.getClient().getEncodedAuthorization());
|
||||
assertEquals("", github.getClient().login);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ package org.kohsuke.github;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
@@ -10,6 +12,9 @@ import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
@@ -19,6 +24,34 @@ import static org.junit.Assert.fail;
|
||||
*/
|
||||
public class GitHubStaticTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
@Test
|
||||
public void testParseURL() throws Exception {
|
||||
assertThat(GitHubClient.parseURL("https://api.github.com"), equalTo(new URL("https://api.github.com")));
|
||||
assertThat(GitHubClient.parseURL(null), nullValue());
|
||||
|
||||
try {
|
||||
GitHubClient.parseURL("bogus");
|
||||
fail();
|
||||
} catch (IllegalStateException e) {
|
||||
assertThat(e.getMessage(), equalTo("Invalid URL: bogus"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseInstant() throws Exception {
|
||||
assertThat(GitHubClient.parseInstant(null), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRawUrlPathInvalid() throws Exception {
|
||||
try {
|
||||
gitHub.createRequest().setRawUrlPath("invalid.path.com");
|
||||
fail();
|
||||
} catch (GHException e) {
|
||||
assertThat(e.getMessage(), equalTo("Raw URL must start with 'http'"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeRoundTrip() throws Exception {
|
||||
final long stableInstantEpochMilli = 1533721222255L;
|
||||
@@ -78,6 +111,62 @@ public class GitHubStaticTest extends AbstractGitHubWireMockTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromRecord() throws Exception {
|
||||
final long stableInstantEpochSeconds = 11610674762L;
|
||||
|
||||
GHRateLimit rateLimit_none = GHRateLimit.fromRecord(new GHRateLimit.Record(9876,
|
||||
5432,
|
||||
(stableInstantEpochSeconds + Duration.ofMinutes(30).toMillis()) / 1000L), RateLimitTarget.NONE);
|
||||
|
||||
GHRateLimit rateLimit_core = GHRateLimit.fromRecord(new GHRateLimit.Record(9876,
|
||||
5432,
|
||||
(stableInstantEpochSeconds + Duration.ofMinutes(30).toMillis()) / 1000L), RateLimitTarget.CORE);
|
||||
|
||||
GHRateLimit rateLimit_search = GHRateLimit.fromRecord(new GHRateLimit.Record(19876,
|
||||
15432,
|
||||
(stableInstantEpochSeconds + Duration.ofHours(1).toMillis()) / 1000L), RateLimitTarget.SEARCH);
|
||||
|
||||
GHRateLimit rateLimit_graphql = GHRateLimit.fromRecord(new GHRateLimit.Record(29876,
|
||||
25432,
|
||||
(stableInstantEpochSeconds + Duration.ofHours(2).toMillis()) / 1000L), RateLimitTarget.GRAPHQL);
|
||||
|
||||
GHRateLimit rateLimit_integration = GHRateLimit.fromRecord(
|
||||
new GHRateLimit.Record(39876,
|
||||
35432,
|
||||
(stableInstantEpochSeconds + Duration.ofHours(3).toMillis()) / 1000L),
|
||||
RateLimitTarget.INTEGRATION_MANIFEST);
|
||||
|
||||
assertThat(rateLimit_none, equalTo(rateLimit_core));
|
||||
assertThat(rateLimit_none, not(sameInstance(rateLimit_core)));
|
||||
assertTrue(rateLimit_none.hashCode() == rateLimit_core.hashCode());
|
||||
assertTrue(rateLimit_none.equals(rateLimit_core));
|
||||
|
||||
assertThat(rateLimit_none, not(equalTo(rateLimit_search)));
|
||||
|
||||
assertThat(rateLimit_none.getCore(), not(sameInstance(rateLimit_core.getCore())));
|
||||
|
||||
assertThat(rateLimit_core.getRecord(RateLimitTarget.NONE), instanceOf(GHRateLimit.UnknownLimitRecord.class));
|
||||
assertThat(rateLimit_core.getRecord(RateLimitTarget.NONE),
|
||||
sameInstance(rateLimit_none.getRecord(RateLimitTarget.NONE)));
|
||||
|
||||
assertThat(rateLimit_core.getRecord(RateLimitTarget.SEARCH), sameInstance(rateLimit_search.getGraphQL()));
|
||||
assertThat(rateLimit_search.getRecord(RateLimitTarget.GRAPHQL),
|
||||
sameInstance(rateLimit_graphql.getIntegrationManifest()));
|
||||
assertThat(rateLimit_graphql.getRecord(RateLimitTarget.INTEGRATION_MANIFEST),
|
||||
sameInstance(rateLimit_integration.getCore()));
|
||||
assertThat(rateLimit_integration.getRecord(RateLimitTarget.CORE), sameInstance(rateLimit_core.getSearch()));
|
||||
|
||||
assertThat(rateLimit_none.getRecord(RateLimitTarget.CORE).getLimit(), equalTo(9876));
|
||||
assertThat(rateLimit_core.getRecord(RateLimitTarget.CORE).getLimit(), equalTo(9876));
|
||||
assertThat(rateLimit_search.getRecord(RateLimitTarget.SEARCH).getLimit(), equalTo(19876));
|
||||
assertThat(rateLimit_graphql.getRecord(RateLimitTarget.GRAPHQL).getLimit(), equalTo(29876));
|
||||
assertThat(rateLimit_integration.getRecord(RateLimitTarget.INTEGRATION_MANIFEST).getLimit(), equalTo(39876));
|
||||
|
||||
assertThat(rateLimit_core.toString(), containsString("GHRateLimit {core {remaining=5432, limit=9876"));
|
||||
assertThat(rateLimit_core.toString(), containsString("search {remaining=999999, limit=1000000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGitHubRateLimitShouldReplaceRateLimit() throws Exception {
|
||||
|
||||
@@ -225,7 +314,7 @@ public class GitHubStaticTest extends AbstractGitHubWireMockTest {
|
||||
// this makes sure they don't break.
|
||||
|
||||
GHRepository repo = getTempRepository();
|
||||
assertThat(repo.root, not(nullValue()));
|
||||
assertThat(repo.getRoot(), not(nullValue()));
|
||||
assertThat(repo.getResponseHeaderFields(), not(nullValue()));
|
||||
|
||||
String repoString = GitHub.getMappingObjectWriter().writeValueAsString(repo);
|
||||
@@ -237,13 +326,13 @@ public class GitHubStaticTest extends AbstractGitHubWireMockTest {
|
||||
.readValue(repoString);
|
||||
|
||||
// This should never happen if the internal method isn't used
|
||||
assertThat(readRepo.root, nullValue());
|
||||
assertThat(readRepo.getRoot(), nullValue());
|
||||
assertThat(readRepo.getResponseHeaderFields(), nullValue());
|
||||
|
||||
readRepo = GitHub.getMappingObjectReader().forType(GHRepository.class).readValue(repoString);
|
||||
|
||||
// This should never happen if the internal method isn't used
|
||||
assertThat(readRepo.root.getConnector(), equalTo(HttpConnector.OFFLINE));
|
||||
assertThat(readRepo.getRoot().getConnector(), equalTo(HttpConnector.OFFLINE));
|
||||
assertThat(readRepo.getResponseHeaderFields(), nullValue());
|
||||
|
||||
String readRepoString = GitHub.getMappingObjectWriter().writeValueAsString(readRepo);
|
||||
|
||||
@@ -25,6 +25,22 @@ public class GitHubTest extends AbstractGitHubWireMockTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRepository() throws IOException {
|
||||
GHRepository repo = gitHub.getRepository("hub4j/github-api");
|
||||
|
||||
assertThat(repo.getFullName(), equalTo("hub4j/github-api"));
|
||||
|
||||
GHRepository repo2 = gitHub.getRepositoryById(Long.toString(repo.getId()));
|
||||
assertThat(repo2.getFullName(), equalTo("hub4j/github-api"));
|
||||
|
||||
try {
|
||||
gitHub.getRepository("hub4j_github-api");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e.getMessage(), equalTo("Repository name must be in format owner/repo"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOrgs() throws IOException {
|
||||
int iterations = 10;
|
||||
@@ -34,6 +50,18 @@ public class GitHubTest extends AbstractGitHubWireMockTest {
|
||||
// System.out.println(org.getName());
|
||||
}
|
||||
assertThat(orgIds.size(), equalTo(iterations));
|
||||
|
||||
GHOrganization org = gitHub.getOrganization("hub4j");
|
||||
GHOrganization org2 = gitHub.getOrganization("hub4j");
|
||||
assertThat(org.getLogin(), equalTo("hub4j"));
|
||||
// caching
|
||||
assertThat(org, sameInstance(org2));
|
||||
|
||||
gitHub.refreshCache();
|
||||
org2 = gitHub.getOrganization("hub4j");
|
||||
assertThat(org2.getLogin(), equalTo("hub4j"));
|
||||
// cache cleared
|
||||
assertThat(org, not(sameInstance(org2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -24,19 +25,27 @@ public class Github2faTest extends AbstractGitHubWireMockTest {
|
||||
// collide with older tokens
|
||||
|
||||
GHAuthorization token = gitHub
|
||||
.createToken(asList, nameOfToken, "this is a test token created by a unit test", () -> {
|
||||
.createToken(asList, nameOfToken, "https://localhost/this/is/a/test/token", () -> {
|
||||
String data = "111878";
|
||||
// TO UPDATE run this in debugger mode, put a breakpoint here, and enter the OTP you get into the
|
||||
// value of Data
|
||||
return data;
|
||||
});
|
||||
assert token != null;
|
||||
|
||||
assertThat(token, notNullValue());
|
||||
|
||||
for (int i = 0; i < asList.size(); i++) {
|
||||
assertTrue(token.getScopes().get(i).contentEquals(asList.get(i)));
|
||||
}
|
||||
|
||||
String p = token.getToken();
|
||||
assertThat(token.getToken(), equalTo("63042a99d88bf138e6d6cf5788e0dc4e7a5d7309"));
|
||||
assertThat(token.getTokenLastEight(), equalTo("7a5d7309"));
|
||||
assertThat(token.getHashedToken(), equalTo("12b727a23cad7c5a5caabb806d88e722794dede98464aed7f77cbc00dbf031a2"));
|
||||
assertThat(token.getNote(), equalTo("Test2faTokenCreate"));
|
||||
assertThat(token.getNoteUrl().toString(), equalTo("https://localhost/this/is/a/test/token"));
|
||||
assertThat(token.getAppUrl().toString(), equalTo("https://localhost/this/is/a/test/app/token"));
|
||||
assertThat(token.getFingerprint(), nullValue());
|
||||
assertThat(token.getHtmlUrl(), nullValue());
|
||||
|
||||
assert p != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
|
||||
public class LifecycleTest extends AbstractGitHubWireMockTest {
|
||||
@@ -61,6 +61,13 @@ public class LifecycleTest extends AbstractGitHubWireMockTest {
|
||||
List<GHAsset> assets = release.getAssets();
|
||||
assertEquals(1, assets.size());
|
||||
assertEquals("LICENSE.txt", assets.get(0).getName());
|
||||
assertThat(assets.get(0).getSize(), equalTo(1104L));
|
||||
assertThat(assets.get(0).getContentType(), equalTo("application/text"));
|
||||
assertThat(assets.get(0).getState(), equalTo("uploaded"));
|
||||
assertThat(assets.get(0).getDownloadCount(), equalTo(0L));
|
||||
assertThat(assets.get(0).getOwner(), sameInstance(release.getOwner()));
|
||||
assertThat(assets.get(0).getBrowserDownloadUrl(),
|
||||
containsString("/temp-testCreateRepository/releases/download/release_tag/LICENSE.txt"));
|
||||
|
||||
return asset;
|
||||
}
|
||||
@@ -74,6 +81,16 @@ public class LifecycleTest extends AbstractGitHubWireMockTest {
|
||||
assertEquals(1, releases.size());
|
||||
GHRelease release = releases.get(0);
|
||||
assertEquals("Test Release", release.getName());
|
||||
assertThat(release.getBody(), startsWith("How exciting!"));
|
||||
assertThat(release.getOwner(), sameInstance(repository));
|
||||
assertThat(release.getZipballUrl(),
|
||||
endsWith("/repos/hub4j-test-org/temp-testCreateRepository/zipball/release_tag"));
|
||||
assertThat(release.getTarballUrl(),
|
||||
endsWith("/repos/hub4j-test-org/temp-testCreateRepository/tarball/release_tag"));
|
||||
assertThat(release.getTargetCommitish(), equalTo("master"));
|
||||
assertThat(release.getHtmlUrl().toString(),
|
||||
endsWith("/hub4j-test-org/temp-testCreateRepository/releases/tag/release_tag"));
|
||||
|
||||
return release;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.kohsuke.github.authorization.ImmutableAuthorizationProvider;
|
||||
import org.kohsuke.github.authorization.OrgAppInstallationAuthorizationProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
|
||||
public class OrgAppInstallationAuthorizationProviderTest extends AbstractGHAppInstallationTest {
|
||||
|
||||
public OrgAppInstallationAuthorizationProviderTest() {
|
||||
useDefaultGitHub = false;
|
||||
}
|
||||
|
||||
@Test(expected = HttpException.class)
|
||||
public void invalidJWTTokenRaisesException() throws IOException {
|
||||
OrgAppInstallationAuthorizationProvider provider = new OrgAppInstallationAuthorizationProvider(
|
||||
"testOrganization",
|
||||
ImmutableAuthorizationProvider.fromJwtToken("myToken"));
|
||||
gitHub = getGitHubBuilder().withAuthorizationProvider(provider)
|
||||
.withEndpoint(mockGitHub.apiServer().baseUrl())
|
||||
.build();
|
||||
|
||||
provider.getEncodedAuthorization();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validJWTTokenAllowsOauthTokenRequest() throws IOException {
|
||||
OrgAppInstallationAuthorizationProvider provider = new OrgAppInstallationAuthorizationProvider("hub4j-test-org",
|
||||
ImmutableAuthorizationProvider.fromJwtToken("bogus-valid-token"));
|
||||
gitHub = getGitHubBuilder().withAuthorizationProvider(provider)
|
||||
.withEndpoint(mockGitHub.apiServer().baseUrl())
|
||||
.build();
|
||||
String encodedAuthorization = provider.getEncodedAuthorization();
|
||||
|
||||
assertThat(encodedAuthorization, notNullValue());
|
||||
assertThat(encodedAuthorization, equalTo("token v1.9a12d913f980a45a16ac9c3a9d34d9b7sa314cb6"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package org.kohsuke.github.extras.authorization;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.kohsuke.github.AbstractGitHubWireMockTest;
|
||||
import org.kohsuke.github.GitHub;
|
||||
import org.kohsuke.github.HttpException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/*
|
||||
* This test will request an application ensuring that the header for the "Authorization" matches a valid JWT token.
|
||||
* A JWT token in the Authorization header will always start with "ey" which is always the start of the base64
|
||||
* encoding of the JWT Header , so a valid header will look like this:
|
||||
*
|
||||
* <pre>
|
||||
* Authorization: Bearer ey{rest of the header}.{payload}.{signature}
|
||||
* </pre>
|
||||
*
|
||||
* Matched by the regular expression:
|
||||
*
|
||||
* <pre>
|
||||
* ^Bearer (?<JWTHeader>ey\S*)\.(?<JWTPayload>\S*)\.(?<JWTSignature>\S*)$
|
||||
* </pre>
|
||||
*
|
||||
* Which is present in the wiremock matcher. Note that we need to use a matcher because the JWT token is encoded
|
||||
* with a private key and a random nonce, so it will never be the same (under normal conditions). For more
|
||||
* information on the format of a JWT token, see: https://jwt.io/introduction/
|
||||
*/
|
||||
public class JWTTokenProviderTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
private static String TEST_APP_ID_2 = "83009";
|
||||
private static String PRIVATE_KEY_FILE_APP_2 = "/ghapi-test-app-2.private-key.pem";
|
||||
|
||||
@Test
|
||||
public void testAuthorizationHeaderPattern() throws GeneralSecurityException, IOException {
|
||||
// authorization header check is custom
|
||||
snapshotNotAllowed();
|
||||
|
||||
JWTTokenProvider jwtTokenProvider = new JWTTokenProvider(TEST_APP_ID_2,
|
||||
new File(this.getClass().getResource(PRIVATE_KEY_FILE_APP_2).getFile()));
|
||||
GitHub gh = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl())
|
||||
.withAuthorizationProvider(jwtTokenProvider)
|
||||
.build();
|
||||
|
||||
// Request the application, the wiremock matcher will ensure that the header
|
||||
// for the authorization is present and has a the format of a valid JWT token
|
||||
gh.getApp();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIssuedAtSkew() throws GeneralSecurityException, IOException {
|
||||
// TODO: This isn't a great test as it doesn't really check anything in CI
|
||||
// This test was accurate when recorded but it doesn't verify that the jwt token is different
|
||||
// or accurate in anyway.
|
||||
|
||||
JWTTokenProvider jwtTokenProvider = new JWTTokenProvider(TEST_APP_ID_2,
|
||||
new File(this.getClass().getResource(PRIVATE_KEY_FILE_APP_2).getFile())) {
|
||||
|
||||
@Override
|
||||
Instant getIssuedAt(Instant now) {
|
||||
return now.plus(Duration.ofMinutes(2));
|
||||
}
|
||||
};
|
||||
GitHub gh = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl())
|
||||
.withAuthorizationProvider(jwtTokenProvider)
|
||||
.build();
|
||||
|
||||
try {
|
||||
// Request the application, the wiremock matcher will ensure that the header
|
||||
// for the authorization is present and has a the format of a valid JWT token
|
||||
gh.getApp();
|
||||
fail();
|
||||
} catch (HttpException e) {
|
||||
assertThat(e.getResponseCode(), equalTo(401));
|
||||
assertThat(e.getMessage(),
|
||||
containsString(
|
||||
"'Issued at' claim ('iat') must be an Integer representing the time that the assertion was issued"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
23
src/test/java/org/kohsuke/github/internal/EnumUtilsTest.java
Normal file
23
src/test/java/org/kohsuke/github/internal/EnumUtilsTest.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.kohsuke.github.internal;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class EnumUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetEnum() {
|
||||
assertNull(EnumUtils.getNullableEnumOrDefault(TestEnum.class, null, TestEnum.UNKNOWN));
|
||||
assertEquals(TestEnum.UNKNOWN, EnumUtils.getNullableEnumOrDefault(TestEnum.class, "foobar", TestEnum.UNKNOWN));
|
||||
assertEquals(TestEnum.VALUE_1, EnumUtils.getNullableEnumOrDefault(TestEnum.class, "VALUE_1", TestEnum.UNKNOWN));
|
||||
assertEquals(TestEnum.VALUE_1, EnumUtils.getNullableEnumOrDefault(TestEnum.class, "value_1", TestEnum.UNKNOWN));
|
||||
assertEquals(TestEnum.VALUE_2, EnumUtils.getNullableEnumOrDefault(TestEnum.class, "VALUE_2", TestEnum.UNKNOWN));
|
||||
assertEquals(TestEnum.VALUE_2, EnumUtils.getNullableEnumOrDefault(TestEnum.class, "value_2", TestEnum.UNKNOWN));
|
||||
}
|
||||
|
||||
private enum TestEnum {
|
||||
VALUE_1, VALUE_2, UNKNOWN;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import com.github.tomakehurst.wiremock.extension.ResponseTransformer;
|
||||
import com.github.tomakehurst.wiremock.http.*;
|
||||
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
|
||||
import com.google.gson.*;
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -64,6 +65,10 @@ public class GitHubWireMockRule extends WireMockMultiServerRule {
|
||||
return servers.get("uploads");
|
||||
}
|
||||
|
||||
public WireMockServer codeloadServer() {
|
||||
return servers.get("codeload");
|
||||
}
|
||||
|
||||
public boolean isUseProxy() {
|
||||
return GitHubWireMockRule.useProxy;
|
||||
}
|
||||
@@ -88,6 +93,10 @@ public class GitHubWireMockRule extends WireMockMultiServerRule {
|
||||
if (new File(apiServer().getOptions().filesRoot().getPath() + "_uploads").exists() || isUseProxy()) {
|
||||
initializeServer("uploads");
|
||||
}
|
||||
|
||||
if (new File(apiServer().getOptions().filesRoot().getPath() + "_codeload").exists() || isUseProxy()) {
|
||||
initializeServer("codeload");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,6 +115,11 @@ public class GitHubWireMockRule extends WireMockMultiServerRule {
|
||||
if (this.uploadsServer() != null) {
|
||||
this.uploadsServer().stubFor(proxyAllTo("https://uploads.github.com").atPriority(100));
|
||||
}
|
||||
|
||||
if (this.codeloadServer() != null) {
|
||||
this.codeloadServer().stubFor(proxyAllTo("https://codeload.github.com").atPriority(100));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,6 +135,8 @@ public class GitHubWireMockRule extends WireMockMultiServerRule {
|
||||
recordSnapshot(this.rawServer(), "https://raw.githubusercontent.com", true);
|
||||
|
||||
recordSnapshot(this.uploadsServer(), "https://uploads.github.com", false);
|
||||
|
||||
recordSnapshot(this.codeloadServer(), "https://codeload.github.com", true);
|
||||
}
|
||||
|
||||
private void recordSnapshot(WireMockServer server, String target, boolean isRawServer) {
|
||||
@@ -141,7 +157,7 @@ public class GitHubWireMockRule extends WireMockMultiServerRule {
|
||||
.extractTextBodiesOver(255));
|
||||
|
||||
// After taking the snapshot, format the output
|
||||
formatTestResources(new File(this.apiServer().getOptions().filesRoot().getPath()).toPath(), false);
|
||||
formatTestResources(new File(server.getOptions().filesRoot().getPath()).toPath(), isRawServer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,6 +229,10 @@ public class GitHubWireMockRule extends WireMockMultiServerRule {
|
||||
fileText = fileText.replace(this.uploadsServer().baseUrl(), "https://uploads.github.com");
|
||||
}
|
||||
|
||||
if (this.codeloadServer() != null) {
|
||||
fileText = fileText.replace(this.codeloadServer().baseUrl(), "https://codeload.github.com");
|
||||
}
|
||||
|
||||
// point bodyFile in the mapping to the renamed body file
|
||||
if (entry != null && filePath.toString().contains("mappings")) {
|
||||
fileText = fileText.replace("-" + entry.getKey(), "-" + entry.getValue());
|
||||
@@ -263,16 +283,23 @@ public class GitHubWireMockRule extends WireMockMultiServerRule {
|
||||
public String mapToMockGitHub(String body) {
|
||||
body = body.replace("https://api.github.com", this.apiServer().baseUrl());
|
||||
|
||||
if (this.rawServer() != null) {
|
||||
body = body.replace("https://raw.githubusercontent.com", this.rawServer().baseUrl());
|
||||
} else {
|
||||
body = body.replace("https://raw.githubusercontent.com", this.apiServer().baseUrl() + "/raw");
|
||||
}
|
||||
body = replaceTargetServerUrl(body, this.rawServer(), "https://raw.githubusercontent.com", "/raw");
|
||||
|
||||
if (this.uploadsServer() != null) {
|
||||
body = body.replace("https://uploads.github.com", this.uploadsServer().baseUrl());
|
||||
body = replaceTargetServerUrl(body, this.uploadsServer(), "https://uploads.github.com", "/uploads");
|
||||
|
||||
body = replaceTargetServerUrl(body, this.codeloadServer(), "https://codeload.github.com", "/codeload");
|
||||
return body;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String replaceTargetServerUrl(String body,
|
||||
WireMockServer wireMockServer,
|
||||
String rawTarget,
|
||||
String inactiveTarget) {
|
||||
if (wireMockServer != null) {
|
||||
body = body.replace(rawTarget, wireMockServer.baseUrl());
|
||||
} else {
|
||||
body = body.replace("https://uploads.github.com", this.apiServer().baseUrl() + "/uploads");
|
||||
body = body.replace(rawTarget, this.apiServer().baseUrl() + inactiveTarget);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
@@ -294,6 +321,7 @@ public class GitHubWireMockRule extends WireMockMultiServerRule {
|
||||
Collection<HttpHeader> headers = response.getHeaders().all();
|
||||
|
||||
fixListTraversalHeader(response, headers);
|
||||
fixLocationHeader(response, headers);
|
||||
|
||||
if ("application/json".equals(response.getHeaders().getContentTypeHeader().mimeTypePart())) {
|
||||
|
||||
@@ -321,11 +349,20 @@ public class GitHubWireMockRule extends WireMockMultiServerRule {
|
||||
}
|
||||
|
||||
private void fixListTraversalHeader(Response response, Collection<HttpHeader> headers) {
|
||||
// Lists are broken up into pages. The Link header contains urls for previous and next pages.
|
||||
HttpHeader linkHeader = response.getHeaders().getHeader("Link");
|
||||
if (linkHeader.isPresent()) {
|
||||
headers.removeIf(item -> item.keyEquals("Link"));
|
||||
headers.add(HttpHeader.httpHeader("Link",
|
||||
linkHeader.firstValue().replace("https://api.github.com", rule.apiServer().baseUrl())));
|
||||
headers.add(HttpHeader.httpHeader("Link", rule.mapToMockGitHub(linkHeader.firstValue())));
|
||||
}
|
||||
}
|
||||
|
||||
private void fixLocationHeader(Response response, Collection<HttpHeader> headers) {
|
||||
// For redirects, the Location header points to the new target.
|
||||
HttpHeader linkHeader = response.getHeaders().getHeader("Location");
|
||||
if (linkHeader.isPresent()) {
|
||||
headers.removeIf(item -> item.keyEquals("Location"));
|
||||
headers.add(HttpHeader.httpHeader("Location", rule.mapToMockGitHub(linkHeader.firstValue())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": 212656166,
|
||||
"node_id": "MDEwOlJlcG9zaXRvcnkyMTI2NTYxNjY=",
|
||||
"id": 332135400,
|
||||
"node_id": "MDEwOlJlcG9zaXRvcnkzMzIxMzU0MDA=",
|
||||
"name": "github-api-test",
|
||||
"full_name": "hub4j-test-org/github-api-test",
|
||||
"private": false,
|
||||
@@ -8,7 +8,7 @@
|
||||
"login": "hub4j-test-org",
|
||||
"id": 7544739,
|
||||
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
|
||||
"gravatar_id": "",
|
||||
"url": "https://api.github.com/users/hub4j-test-org",
|
||||
"html_url": "https://github.com/hub4j-test-org",
|
||||
@@ -25,7 +25,7 @@
|
||||
"site_admin": false
|
||||
},
|
||||
"html_url": "https://github.com/hub4j-test-org/github-api-test",
|
||||
"description": "A test repository for testing the github-api project",
|
||||
"description": "A test repository for testing the github-api project: github-api-test",
|
||||
"fork": false,
|
||||
"url": "https://api.github.com/repos/hub4j-test-org/github-api-test",
|
||||
"forks_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/forks",
|
||||
@@ -64,9 +64,9 @@
|
||||
"labels_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/labels{/name}",
|
||||
"releases_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/releases{/id}",
|
||||
"deployments_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/deployments",
|
||||
"created_at": "2019-10-03T18:57:53Z",
|
||||
"updated_at": "2019-10-03T18:57:57Z",
|
||||
"pushed_at": "2019-10-03T18:57:54Z",
|
||||
"created_at": "2021-01-23T05:30:23Z",
|
||||
"updated_at": "2021-01-23T05:30:27Z",
|
||||
"pushed_at": "2021-01-23T05:30:25Z",
|
||||
"git_url": "git://github.com/hub4j-test-org/github-api-test.git",
|
||||
"ssh_url": "git@github.com:hub4j-test-org/github-api-test.git",
|
||||
"clone_url": "https://github.com/hub4j-test-org/github-api-test.git",
|
||||
@@ -90,20 +90,22 @@
|
||||
"forks": 0,
|
||||
"open_issues": 0,
|
||||
"watchers": 0,
|
||||
"default_branch": "master",
|
||||
"default_branch": "main",
|
||||
"permissions": {
|
||||
"admin": true,
|
||||
"push": true,
|
||||
"pull": true
|
||||
},
|
||||
"temp_clone_token": "",
|
||||
"allow_squash_merge": true,
|
||||
"allow_merge_commit": true,
|
||||
"allow_rebase_merge": true,
|
||||
"delete_branch_on_merge": false,
|
||||
"organization": {
|
||||
"login": "hub4j-test-org",
|
||||
"id": 7544739,
|
||||
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
|
||||
"gravatar_id": "",
|
||||
"url": "https://api.github.com/users/hub4j-test-org",
|
||||
"html_url": "https://github.com/hub4j-test-org",
|
||||
@@ -120,5 +122,5 @@
|
||||
"site_admin": false
|
||||
},
|
||||
"network_count": 0,
|
||||
"subscribers_count": 2
|
||||
"subscribers_count": 9
|
||||
}
|
||||
@@ -1,38 +1,39 @@
|
||||
{
|
||||
"url": "http://localhost:62379/repos/hub4j-test-org/github-api-test/deployments/173089055",
|
||||
"id": 173089055,
|
||||
"node_id": "MDEwOkRlcGxveW1lbnQxNzMwODkwNTU=",
|
||||
"sha": "a446d9fa5c6f43d5f9333b625606909cd4635071",
|
||||
"ref": "master",
|
||||
"url": "https://api.github.com/repos/hub4j-test-org/github-api-test/deployments/315601563",
|
||||
"id": 315601563,
|
||||
"node_id": "MDEwOkRlcGxveW1lbnQzMTU2MDE1NjM=",
|
||||
"task": "deploy",
|
||||
"payload": "{\"user\":\"atmos\",\"room_id\":123456}",
|
||||
"original_environment": "unittest",
|
||||
"environment": "unittest",
|
||||
"description": "question",
|
||||
"created_at": "2021-01-23T05:30:28Z",
|
||||
"updated_at": "2021-01-23T05:30:28Z",
|
||||
"statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/deployments/315601563/statuses",
|
||||
"repository_url": "https://api.github.com/repos/hub4j-test-org/github-api-test",
|
||||
"creator": {
|
||||
"login": "bitwiseman",
|
||||
"id": 1958953,
|
||||
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/1958953?v=4",
|
||||
"gravatar_id": "",
|
||||
"url": "http://localhost:62379/users/bitwiseman",
|
||||
"url": "https://api.github.com/users/bitwiseman",
|
||||
"html_url": "https://github.com/bitwiseman",
|
||||
"followers_url": "http://localhost:62379/users/bitwiseman/followers",
|
||||
"following_url": "http://localhost:62379/users/bitwiseman/following{/other_user}",
|
||||
"gists_url": "http://localhost:62379/users/bitwiseman/gists{/gist_id}",
|
||||
"starred_url": "http://localhost:62379/users/bitwiseman/starred{/owner}{/repo}",
|
||||
"subscriptions_url": "http://localhost:62379/users/bitwiseman/subscriptions",
|
||||
"organizations_url": "http://localhost:62379/users/bitwiseman/orgs",
|
||||
"repos_url": "http://localhost:62379/users/bitwiseman/repos",
|
||||
"events_url": "http://localhost:62379/users/bitwiseman/events{/privacy}",
|
||||
"received_events_url": "http://localhost:62379/users/bitwiseman/received_events",
|
||||
"followers_url": "https://api.github.com/users/bitwiseman/followers",
|
||||
"following_url": "https://api.github.com/users/bitwiseman/following{/other_user}",
|
||||
"gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}",
|
||||
"starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}",
|
||||
"subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions",
|
||||
"organizations_url": "https://api.github.com/users/bitwiseman/orgs",
|
||||
"repos_url": "https://api.github.com/users/bitwiseman/repos",
|
||||
"events_url": "https://api.github.com/users/bitwiseman/events{/privacy}",
|
||||
"received_events_url": "https://api.github.com/users/bitwiseman/received_events",
|
||||
"type": "User",
|
||||
"site_admin": false
|
||||
},
|
||||
"created_at": "2019-10-03T18:57:57Z",
|
||||
"updated_at": "2019-10-03T18:57:57Z",
|
||||
"statuses_url": "http://localhost:62379/repos/hub4j-test-org/github-api-test/deployments/173089055/statuses",
|
||||
"repository_url": "http://localhost:62379/repos/hub4j-test-org/github-api-test",
|
||||
"transient_environment": true,
|
||||
"production_environment": false
|
||||
"sha": "e53a04ca0ba2fbe6ea3fd590e8ea1391ac61630f",
|
||||
"ref": "main",
|
||||
"payload": "{\"user\":\"atmos\",\"room_id\":123456}",
|
||||
"transient_environment": false,
|
||||
"production_environment": false,
|
||||
"performed_via_github_app": null
|
||||
}
|
||||
@@ -1,20 +1,21 @@
|
||||
[
|
||||
{
|
||||
"url": "https://api.github.com/repos/hub4j-test-org/github-api-test/deployments/173089055",
|
||||
"id": 173089055,
|
||||
"node_id": "MDEwOkRlcGxveW1lbnQxNzMwODkwNTU=",
|
||||
"sha": "a446d9fa5c6f43d5f9333b625606909cd4635071",
|
||||
"ref": "master",
|
||||
"url": "https://api.github.com/repos/hub4j-test-org/github-api-test/deployments/315601563",
|
||||
"id": 315601563,
|
||||
"node_id": "MDEwOkRlcGxveW1lbnQzMTU2MDE1NjM=",
|
||||
"task": "deploy",
|
||||
"payload": "{\"user\":\"atmos\",\"room_id\":123456}",
|
||||
"original_environment": "unittest",
|
||||
"environment": "unittest",
|
||||
"description": "question",
|
||||
"created_at": "2021-01-23T05:30:28Z",
|
||||
"updated_at": "2021-01-23T05:30:28Z",
|
||||
"statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/deployments/315601563/statuses",
|
||||
"repository_url": "https://api.github.com/repos/hub4j-test-org/github-api-test",
|
||||
"creator": {
|
||||
"login": "bitwiseman",
|
||||
"id": 1958953,
|
||||
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/1958953?v=4",
|
||||
"gravatar_id": "",
|
||||
"url": "https://api.github.com/users/bitwiseman",
|
||||
"html_url": "https://github.com/bitwiseman",
|
||||
@@ -30,11 +31,11 @@
|
||||
"type": "User",
|
||||
"site_admin": false
|
||||
},
|
||||
"created_at": "2019-10-03T18:57:57Z",
|
||||
"updated_at": "2019-10-03T18:57:57Z",
|
||||
"statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/deployments/173089055/statuses",
|
||||
"repository_url": "https://api.github.com/repos/hub4j-test-org/github-api-test",
|
||||
"transient_environment": true,
|
||||
"production_environment": false
|
||||
"sha": "e53a04ca0ba2fbe6ea3fd590e8ea1391ac61630f",
|
||||
"ref": "main",
|
||||
"payload": "{\"user\":\"atmos\",\"room_id\":123456}",
|
||||
"transient_environment": false,
|
||||
"production_environment": false,
|
||||
"performed_via_github_app": null
|
||||
}
|
||||
]
|
||||
@@ -2,7 +2,7 @@
|
||||
"login": "bitwiseman",
|
||||
"id": 1958953,
|
||||
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/1958953?v=4",
|
||||
"gravatar_id": "",
|
||||
"url": "https://api.github.com/users/bitwiseman",
|
||||
"html_url": "https://github.com/bitwiseman",
|
||||
@@ -23,17 +23,18 @@
|
||||
"location": "Seattle, WA, USA",
|
||||
"email": "bitwiseman@gmail.com",
|
||||
"hireable": null,
|
||||
"bio": "https://twitter.com/bitwiseman",
|
||||
"public_repos": 167,
|
||||
"public_gists": 4,
|
||||
"followers": 136,
|
||||
"following": 9,
|
||||
"bio": null,
|
||||
"twitter_username": "bitwiseman",
|
||||
"public_repos": 201,
|
||||
"public_gists": 7,
|
||||
"followers": 176,
|
||||
"following": 11,
|
||||
"created_at": "2012-07-11T20:38:33Z",
|
||||
"updated_at": "2019-09-24T19:32:29Z",
|
||||
"private_gists": 7,
|
||||
"total_private_repos": 9,
|
||||
"updated_at": "2021-01-22T16:38:42Z",
|
||||
"private_gists": 19,
|
||||
"total_private_repos": 17,
|
||||
"owned_private_repos": 0,
|
||||
"disk_usage": 33697,
|
||||
"disk_usage": 33700,
|
||||
"collaborators": 0,
|
||||
"two_factor_authentication": true,
|
||||
"plan": {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user