mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-13 15:50:09 +00:00
Compare commits
454 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d667b2f822 | ||
|
|
d7f511363d | ||
|
|
39e7c5c3de | ||
|
|
60acd5c864 | ||
|
|
b92cf6fd35 | ||
|
|
f7d048e0b9 | ||
|
|
b3d79622e6 | ||
|
|
7e7ae79477 | ||
|
|
5910988314 | ||
|
|
8c4b1ef74a | ||
|
|
7d4f1941e7 | ||
|
|
eedefcdbbb | ||
|
|
bdb5e82abc | ||
|
|
ff766a46c8 | ||
|
|
0a40dc5939 | ||
|
|
71862d76d3 | ||
|
|
7a35cc3d17 | ||
|
|
7a4870c977 | ||
|
|
d4d2792498 | ||
|
|
a969509283 | ||
|
|
82fa340c07 | ||
|
|
d44cd4a827 | ||
|
|
a8dbe65e30 | ||
|
|
d2ce7c11ac | ||
|
|
d02af5ccb0 | ||
|
|
9a5467dcac | ||
|
|
2af4f61882 | ||
|
|
cbd06eef96 | ||
|
|
392dc2a040 | ||
|
|
da11702f68 | ||
|
|
f262bf7cdb | ||
|
|
78ab5ad156 | ||
|
|
6af796fc3b | ||
|
|
c174be37b3 | ||
|
|
18aa067c44 | ||
|
|
8d50b338f4 | ||
|
|
37d7cfaaf2 | ||
|
|
d3564a9a4f | ||
|
|
39d6dd9916 | ||
|
|
0152ebf062 | ||
|
|
757b9b2118 | ||
|
|
f6a01551fd | ||
|
|
1f619f3801 | ||
|
|
fd436cf5b2 | ||
|
|
7e05ce38cf | ||
|
|
7d1e977ffe | ||
|
|
6c2ce83b45 | ||
|
|
d5ba0eebcb | ||
|
|
432585cb75 | ||
|
|
e41a341ce6 | ||
|
|
6aad80904a | ||
|
|
20e796cef4 | ||
|
|
a3b126282d | ||
|
|
5f597379b5 | ||
|
|
9d8460bb81 | ||
|
|
8943af9840 | ||
|
|
d23c718036 | ||
|
|
834c84c9ea | ||
|
|
adc436a3f5 | ||
|
|
e325bf7771 | ||
|
|
feabd07a21 | ||
|
|
e138c6fd61 | ||
|
|
d32299fde5 | ||
|
|
3d7d780e8f | ||
|
|
9f49854033 | ||
|
|
1fe820d463 | ||
|
|
4a78690fde | ||
|
|
3dcaf5a9de | ||
|
|
ff788852d6 | ||
|
|
5ae062719e | ||
|
|
421c0a11fb | ||
|
|
6ae586aeb7 | ||
|
|
7036423084 | ||
|
|
2f118a9cbe | ||
|
|
2c50255b21 | ||
|
|
8cb7210c46 | ||
|
|
ad0a24ad2f | ||
|
|
df6c951830 | ||
|
|
5da2caa616 | ||
|
|
a3fe95d1e4 | ||
|
|
38e61c121b | ||
|
|
03e9623073 | ||
|
|
93a1657e1e | ||
|
|
91d67fb72f | ||
|
|
d8cc1f885c | ||
|
|
c1f999d896 | ||
|
|
efc4d0f59b | ||
|
|
cf55d670b9 | ||
|
|
8567c5e6a1 | ||
|
|
331084fefd | ||
|
|
62bf691ac1 | ||
|
|
09b41d4665 | ||
|
|
71645240e9 | ||
|
|
603468823d | ||
|
|
01f464cc69 | ||
|
|
57ac6e982f | ||
|
|
319d2d1efe | ||
|
|
37de3a4122 | ||
|
|
bb3a49264d | ||
|
|
9cecce74fa | ||
|
|
f9cf2878ef | ||
|
|
9c80b7cf54 | ||
|
|
1ecad7031f | ||
|
|
c85d6107ec | ||
|
|
7b7445b601 | ||
|
|
1ab474673d | ||
|
|
dbf92e7f20 | ||
|
|
6c42db2508 | ||
|
|
c9a42178e8 | ||
|
|
eff48dfe67 | ||
|
|
0c38bdc068 | ||
|
|
b8e1736696 | ||
|
|
c2f36444d0 | ||
|
|
5dc74f5b4d | ||
|
|
9694dfe4cc | ||
|
|
734125ea14 | ||
|
|
438f5d1b87 | ||
|
|
fadd6d7978 | ||
|
|
5026262273 | ||
|
|
5b53fba020 | ||
|
|
3892e6e16f | ||
|
|
33467de763 | ||
|
|
f3528d97c2 | ||
|
|
6fb3b01bf0 | ||
|
|
e3c9cec440 | ||
|
|
0e011425fb | ||
|
|
ba658f7fea | ||
|
|
0e6087143b | ||
|
|
5f967e6307 | ||
|
|
2eb8ce632c | ||
|
|
f25dbd15d9 | ||
|
|
cc5ea77170 | ||
|
|
e323644af2 | ||
|
|
61f3a3219f | ||
|
|
4dcf5dbc13 | ||
|
|
8faecba0a2 | ||
|
|
739551cbe3 | ||
|
|
24a2e42881 | ||
|
|
6921754c99 | ||
|
|
d8827a0b44 | ||
|
|
a48091988f | ||
|
|
9bd9c9cf1f | ||
|
|
695692285b | ||
|
|
03edacf7b6 | ||
|
|
4802c97e89 | ||
|
|
9fc24d1981 | ||
|
|
d4ddf453b0 | ||
|
|
c0117f07cf | ||
|
|
8a88c14b13 | ||
|
|
a5b6302a69 | ||
|
|
9f29d4619d | ||
|
|
f4b9dd7d7b | ||
|
|
c0a4152b00 | ||
|
|
efb87c5a9e | ||
|
|
061e8bb662 | ||
|
|
a4f42b2948 | ||
|
|
cb2fcd3a9e | ||
|
|
1d004a35a0 | ||
|
|
c763c02018 | ||
|
|
eb36cb4436 | ||
|
|
72d4b9bf62 | ||
|
|
81ea138f41 | ||
|
|
1bbc66ad62 | ||
|
|
e7348df372 | ||
|
|
550e060647 | ||
|
|
2970a58e95 | ||
|
|
e0efa04fd4 | ||
|
|
4d24088982 | ||
|
|
baba9f5de6 | ||
|
|
c35cd63d0e | ||
|
|
80fa389ce3 | ||
|
|
8ec861c9fe | ||
|
|
837400fb5e | ||
|
|
ec4525b8ff | ||
|
|
281c927971 | ||
|
|
9dd44c13e4 | ||
|
|
f28edbcf8f | ||
|
|
29e147f992 | ||
|
|
830f4231e1 | ||
|
|
7d65e31055 | ||
|
|
dec7a91b5b | ||
|
|
1ba630c221 | ||
|
|
7d3387fb96 | ||
|
|
a0c0de28d7 | ||
|
|
dc31d52f83 | ||
|
|
620c822dac | ||
|
|
5990f5ae22 | ||
|
|
37329a50d4 | ||
|
|
550597f72e | ||
|
|
2aa4022e2c | ||
|
|
b40741b14d | ||
|
|
3c739d889e | ||
|
|
24a92a133e | ||
|
|
ce97eb5b40 | ||
|
|
7a4e3c480e | ||
|
|
eefa710839 | ||
|
|
4c3e1afcca | ||
|
|
c1a77ada5d | ||
|
|
5671e5ed67 | ||
|
|
2fdc5a8541 | ||
|
|
297dbae247 | ||
|
|
0910cdf3a4 | ||
|
|
6877fb5c74 | ||
|
|
2d65daa8c9 | ||
|
|
dab4cb6186 | ||
|
|
40773a2b49 | ||
|
|
7e0d61a6fc | ||
|
|
7f9620d75f | ||
|
|
3559aef1a1 | ||
|
|
94ceb5eaaf | ||
|
|
778ca76d22 | ||
|
|
b1c0e41c5c | ||
|
|
f826edd097 | ||
|
|
edc7c4a4b8 | ||
|
|
dafdc66d25 | ||
|
|
0d135f14bb | ||
|
|
568c08d0e9 | ||
|
|
87410e295e | ||
|
|
b163e68950 | ||
|
|
88b006e957 | ||
|
|
477f2f2814 | ||
|
|
933d99c23b | ||
|
|
d3a0c5ded1 | ||
|
|
1e173ddc24 | ||
|
|
ca404cb33b | ||
|
|
f0dc7d5b02 | ||
|
|
933702376f | ||
|
|
e08896775b | ||
|
|
d610e46f8e | ||
|
|
7d1989f5a2 | ||
|
|
5c1e371427 | ||
|
|
dbd9d51747 | ||
|
|
fdf5d3f72d | ||
|
|
2719867a86 | ||
|
|
0240412ad2 | ||
|
|
7c065c1205 | ||
|
|
f9aa1ad1f2 | ||
|
|
5feffdf544 | ||
|
|
4e56b8bb78 | ||
|
|
845017313c | ||
|
|
dc2830d94f | ||
|
|
552edf8698 | ||
|
|
41c51646fe | ||
|
|
a42024bdbc | ||
|
|
20cfb26a7f | ||
|
|
3972d11827 | ||
|
|
5cc88a0075 | ||
|
|
fc08711111 | ||
|
|
b20c2babec | ||
|
|
cb0facc6ef | ||
|
|
78abb2edcb | ||
|
|
7d350d9def | ||
|
|
48d7daf2c4 | ||
|
|
2782059d88 | ||
|
|
0ca10bc2ac | ||
|
|
880abe2305 | ||
|
|
22f61d6225 | ||
|
|
4fbaa425fb | ||
|
|
e81e228f03 | ||
|
|
1076f89954 | ||
|
|
9c6f977202 | ||
|
|
bd23ba6077 | ||
|
|
c7af56d0ed | ||
|
|
8da6db9fcc | ||
|
|
2fe7342fd7 | ||
|
|
f6221144a8 | ||
|
|
872d713e50 | ||
|
|
d5b04f572b | ||
|
|
0f7a5f1c08 | ||
|
|
a163c565a8 | ||
|
|
413a316b15 | ||
|
|
65a92a49b5 | ||
|
|
563507ca21 | ||
|
|
21b2d02f0a | ||
|
|
19e1a00fd7 | ||
|
|
a02a6a22d0 | ||
|
|
3488421f67 | ||
|
|
34a961088c | ||
|
|
b35509150a | ||
|
|
d096aa2065 | ||
|
|
efd5bef102 | ||
|
|
b8c6e44ab6 | ||
|
|
9a91cc43e2 | ||
|
|
f4cbab52a7 | ||
|
|
57b58cf203 | ||
|
|
9ba8ae08a1 | ||
|
|
dfe81f510e | ||
|
|
f3a0b35442 | ||
|
|
64e3be3bc7 | ||
|
|
4c82d1c56e | ||
|
|
d8451fc2f5 | ||
|
|
8078423252 | ||
|
|
68176b5695 | ||
|
|
1bf7833959 | ||
|
|
89770b922d | ||
|
|
716947bbb1 | ||
|
|
47e0d7786b | ||
|
|
55f9c40bba | ||
|
|
51afa30732 | ||
|
|
23c07316ee | ||
|
|
e740f52e5e | ||
|
|
a731109747 | ||
|
|
a50a011eb3 | ||
|
|
e22c6d3a94 | ||
|
|
50fb9c1795 | ||
|
|
22575c9a01 | ||
|
|
2934922cb5 | ||
|
|
9042ff46c7 | ||
|
|
a1a91539c2 | ||
|
|
468f4f94a3 | ||
|
|
3ebd35437e | ||
|
|
a166bbadad | ||
|
|
7ff07a132a | ||
|
|
6f297bcbb8 | ||
|
|
1c023e15af | ||
|
|
37f96848a7 | ||
|
|
3d04765f51 | ||
|
|
e1152fa549 | ||
|
|
ab47896f17 | ||
|
|
4f13565e51 | ||
|
|
7ab93a59e2 | ||
|
|
943c0d022b | ||
|
|
bea8922c39 | ||
|
|
97c96a7ee1 | ||
|
|
3d831ba7e8 | ||
|
|
df749a98cb | ||
|
|
22bbc9c621 | ||
|
|
30def4e515 | ||
|
|
cf8be37310 | ||
|
|
12409df446 | ||
|
|
3452a08de3 | ||
|
|
425ea0579e | ||
|
|
22afb769af | ||
|
|
884eae269e | ||
|
|
59a973970e | ||
|
|
225383464a | ||
|
|
3d82731325 | ||
|
|
dacdf08309 | ||
|
|
ad281adc97 | ||
|
|
80741c7773 | ||
|
|
532f7a4b17 | ||
|
|
5e87d582e4 | ||
|
|
b9bf47aaca | ||
|
|
0dba882817 | ||
|
|
c419883814 | ||
|
|
6f0ccbf2b5 | ||
|
|
54332c0bd1 | ||
|
|
5f80674e89 | ||
|
|
c4d0d8ff06 | ||
|
|
8ac1b7082a | ||
|
|
f146ae8be4 | ||
|
|
e7728fdc94 | ||
|
|
052122e4d0 | ||
|
|
38827d2b3d | ||
|
|
9e1f16be27 | ||
|
|
c845846317 | ||
|
|
9276556f19 | ||
|
|
c796d18948 | ||
|
|
8dee5520cf | ||
|
|
440e13714e | ||
|
|
44a70b372d | ||
|
|
504286e96e | ||
|
|
ffdd54d2fa | ||
|
|
32804b81c0 | ||
|
|
403b22ade0 | ||
|
|
a4e74abcca | ||
|
|
8dcef5bac0 | ||
|
|
49878bc4e3 | ||
|
|
3f1a71c8a4 | ||
|
|
bf9b2c0da3 | ||
|
|
909a274709 | ||
|
|
fc529b8083 | ||
|
|
f1386f26fb | ||
|
|
cccd09d329 | ||
|
|
0fccf7effe | ||
|
|
4b91a47c8b | ||
|
|
bd40499bbe | ||
|
|
c7c8cd76c6 | ||
|
|
0bb9f0ce41 | ||
|
|
7136afce8e | ||
|
|
ec17c1de6a | ||
|
|
8d6daef354 | ||
|
|
3a09d2de4a | ||
|
|
c78e10f92e | ||
|
|
b113ff35ac | ||
|
|
6360024d20 | ||
|
|
a7683f6bd7 | ||
|
|
e46a9f3f2a | ||
|
|
a8d711d4c8 | ||
|
|
df74fc67bd | ||
|
|
450261abbf | ||
|
|
12230edc54 | ||
|
|
d1cfcf561b | ||
|
|
d143f5af8b | ||
|
|
0f7ae3cda7 | ||
|
|
baf94e56c8 | ||
|
|
905bd1a4c9 | ||
|
|
96bcf24047 | ||
|
|
dfe47235cf | ||
|
|
b82ea8eaa8 | ||
|
|
b1b830c268 | ||
|
|
e654d4a6df | ||
|
|
ac30b17ecb | ||
|
|
95efdb3a51 | ||
|
|
49c165e203 | ||
|
|
a4be351d9f | ||
|
|
3d0401aecd | ||
|
|
7c27572a53 | ||
|
|
1e7760012e | ||
|
|
24d464b6e5 | ||
|
|
499d91f9f8 | ||
|
|
8e0ceaa06b | ||
|
|
4e62641f7e | ||
|
|
688644f5a4 | ||
|
|
4703f2d1f5 | ||
|
|
14149ae949 | ||
|
|
a0fb0d170c | ||
|
|
e133afec86 | ||
|
|
3ae8ee8ddb | ||
|
|
012643a231 | ||
|
|
dccb43f4dc | ||
|
|
15b3bc6a63 | ||
|
|
2d15bef76d | ||
|
|
756d298f04 | ||
|
|
9f35eb1a85 | ||
|
|
c905bb4b6c | ||
|
|
c78af01c8f | ||
|
|
084855645a | ||
|
|
afce9ece89 | ||
|
|
154e50e36d | ||
|
|
80a129102b | ||
|
|
93672a074e | ||
|
|
c7f6f6233c | ||
|
|
68915a9daf | ||
|
|
13eb91f8dd | ||
|
|
1a8355e6fb | ||
|
|
aa2b7ae60a | ||
|
|
acd36b7ea5 | ||
|
|
87245ab79f | ||
|
|
13b6a17827 | ||
|
|
615e4cf24e | ||
|
|
0e6d08f027 | ||
|
|
d593e584dd | ||
|
|
e046b97160 | ||
|
|
567d3dac55 | ||
|
|
a67a0aa924 | ||
|
|
1b1e3e88fe | ||
|
|
ec99636ef0 | ||
|
|
9d955d252a | ||
|
|
f136f6837a | ||
|
|
6fc1fb0966 | ||
|
|
fad203a66d | ||
|
|
71304b114a | ||
|
|
2497ac68d1 |
29
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
29
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Desktop (please complete the following information):**
|
||||||
|
- OS: [e.g. iOS]
|
||||||
|
- Browser [e.g. chrome, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
10
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
10
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Description
|
||||||
|
** Describe your change here**
|
||||||
|
|
||||||
|
# Before submitting a PR:
|
||||||
|
We love getting PRs, but we hate asking people for the same basic changes every time.
|
||||||
|
|
||||||
|
- [ ] 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 install site` locally. This may reformat your code, commit those changes. If this command doesn't succeed, your change will not pass CI.
|
||||||
19
.github/release-drafter.yml
vendored
Normal file
19
.github/release-drafter.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
name-template: 'v$NEXT_PATCH_VERSION 🌈'
|
||||||
|
tag-template: 'v$NEXT_PATCH_VERSION'
|
||||||
|
categories:
|
||||||
|
- title: '🚀 Features'
|
||||||
|
labels:
|
||||||
|
- 'feature'
|
||||||
|
- 'enhancement'
|
||||||
|
- title: '🐛 Bug Fixes'
|
||||||
|
labels:
|
||||||
|
- 'fix'
|
||||||
|
- 'bugfix'
|
||||||
|
- 'bug'
|
||||||
|
- title: '🧰 Maintenance'
|
||||||
|
label: 'chore'
|
||||||
|
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
|
||||||
|
template: |
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
$CHANGES
|
||||||
22
.github/workflows/maven-build.yml
vendored
Normal file
22
.github/workflows/maven-build.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
name: Java CI Build and Test
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
java: [ '1.8.0', '11.0.x', '13.0.x' ]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: Set up JDK
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: ${{ matrix.java }}
|
||||||
|
- name: Maven Download all dependencies
|
||||||
|
run: mvn -B org.apache.maven.plugins:maven-dependency-plugin:3.1.1:go-offline
|
||||||
|
- name: Maven Build
|
||||||
|
run: mvn -B install site -P ci --file pom.xml
|
||||||
1174
CHANGELOG.md
Normal file
1174
CHANGELOG.md
Normal file
File diff suppressed because it is too large
Load Diff
76
CODE_OF_CONDUCT.md
Normal file
76
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
In the interest of fostering an open and welcoming environment, we as
|
||||||
|
contributors and maintainers pledge to making participation in our project and
|
||||||
|
our community a harassment-free experience for everyone, regardless of age, body
|
||||||
|
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
||||||
|
level of experience, education, socio-economic status, nationality, personal
|
||||||
|
appearance, race, religion, or sexual identity and orientation.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to creating a positive environment
|
||||||
|
include:
|
||||||
|
|
||||||
|
* Using welcoming and inclusive language
|
||||||
|
* Being respectful of differing viewpoints and experiences
|
||||||
|
* Gracefully accepting constructive criticism
|
||||||
|
* Focusing on what is best for the community
|
||||||
|
* Showing empathy towards other community members
|
||||||
|
|
||||||
|
Examples of unacceptable behavior by participants include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||||
|
advances
|
||||||
|
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or electronic
|
||||||
|
address, without explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a
|
||||||
|
professional setting
|
||||||
|
|
||||||
|
## Our Responsibilities
|
||||||
|
|
||||||
|
Project maintainers are responsible for clarifying the standards of acceptable
|
||||||
|
behavior and are expected to take appropriate and fair corrective action in
|
||||||
|
response to any instances of unacceptable behavior.
|
||||||
|
|
||||||
|
Project maintainers have the right and responsibility to remove, edit, or
|
||||||
|
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||||
|
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||||
|
permanently any contributor for other behaviors that they deem inappropriate,
|
||||||
|
threatening, offensive, or harmful.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies both within project spaces and in public spaces
|
||||||
|
when an individual is representing the project or its community. Examples of
|
||||||
|
representing a project or community include using an official project e-mail
|
||||||
|
address, posting via an official social media account, or acting as an appointed
|
||||||
|
representative at an online or offline event. Representation of a project may be
|
||||||
|
further defined and clarified by project maintainers.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
|
reported by contacting the project team at bitwiseman@gmail.com. All
|
||||||
|
complaints will be reviewed and investigated and will result in a response that
|
||||||
|
is deemed necessary and appropriate to the circumstances. The project team is
|
||||||
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||||
|
Further details of specific enforcement policies may be posted separately.
|
||||||
|
|
||||||
|
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||||
|
faith may face temporary or permanent repercussions as determined by other
|
||||||
|
members of the project's leadership.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||||
|
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||||
|
|
||||||
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
|
||||||
|
For answers to common questions about this code of conduct, see
|
||||||
|
https://www.contributor-covenant.org/faq
|
||||||
62
CONTRIBUTING.md
Normal file
62
CONTRIBUTING.md
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
## Using WireMock and Snapshots
|
||||||
|
|
||||||
|
This project has started converting to using WireMock to stub out http responses instead of use live data.
|
||||||
|
This change will allow tests to run in a CI environment without needing to touch github.com.
|
||||||
|
The tests will instead serve previously recorded responses from local data files.
|
||||||
|
|
||||||
|
### Running WireMock tests
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
`mvn install -Dtest=WireMockStatusReporterTest`
|
||||||
|
|
||||||
|
This the default behavior.
|
||||||
|
|
||||||
|
|
||||||
|
### Setting up credential
|
||||||
|
|
||||||
|
1. Create an OAuth token on github.com
|
||||||
|
2. Set the GITHUB_OAUTH environment variable to the value of that token
|
||||||
|
3. Set the system property `test.github.useProxy` (usually like "-Dtest.github.useProxy" as a Java VM option)
|
||||||
|
|
||||||
|
`mvn install -Dtest.github.useProxy -Dtest=WireMockStatusReporterTest`
|
||||||
|
|
||||||
|
4. The above should report no test failures and include the following console output:
|
||||||
|
|
||||||
|
`WireMockStatusReporterTest: GitHub proxying and user auth correctly configured for user login: <your login>`
|
||||||
|
|
||||||
|
Whenever you run tests with `-Dtest.github.useProxy`, they will try to get data from local files but will fallback to proxying to github if not found.
|
||||||
|
|
||||||
|
|
||||||
|
### Writing a new test
|
||||||
|
|
||||||
|
Once you have credentials setup, you add new test classes and test methods as you would normally.
|
||||||
|
Keep `useProxy` enabled and iterate on your tests as needed. Remember, while proxying your tests are interacting with GitHub - you will need to clean up your state between runs.
|
||||||
|
|
||||||
|
When you are ready to create a snapshot of your test data,
|
||||||
|
run your test with `test.github.takeSnapshot` ("-Dtest.github.takeSnapshot" as a Java VM option). For example:
|
||||||
|
|
||||||
|
`mvn install -Dtest.github.takeSnapshot -Dtest=YourTestClassName`
|
||||||
|
|
||||||
|
The above command would create snapshot WireMock data files under the path `src/test/resources/org/kohsuhke/github/YourTestClassName/wiremock`.
|
||||||
|
Each method would get a separate director that would hold the data files for that test method.
|
||||||
|
|
||||||
|
Add all files including the generated data to your commit and submit a PR.
|
||||||
|
|
||||||
|
### Modifying existing tests
|
||||||
|
|
||||||
|
When modifying existing tests, you can change the stubbed WireMock data files by hand or you can try generating a new snapshot.
|
||||||
|
|
||||||
|
#### Manual editing of data (minor changes only)
|
||||||
|
|
||||||
|
If you know what data will change, it is sometimes simplest to make any required changes to the data files manually.
|
||||||
|
This can be easier if the changes are minor or when you development environment is not setup to to take updated snapshots.
|
||||||
|
|
||||||
|
#### Generating a new snapshot
|
||||||
|
|
||||||
|
For more most changes, it is recommended to take a new snapshot when updating tests.
|
||||||
|
Delete the wiremock data files for the test method you will be modifying.
|
||||||
|
For more significant changes, you can even delete the WireMock files for an entire test class.
|
||||||
|
Then follow the same as when writing a new test: run with proxy enabled to debug, take a new snapshot when done, commit everything, and submit the PR.
|
||||||
3
README
3
README
@@ -1,3 +0,0 @@
|
|||||||
Java API for GitHub
|
|
||||||
|
|
||||||
See http://github-api.kohsuke.org/ for more details
|
|
||||||
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Java API for GitHub
|
||||||
|
|
||||||
|
[](https://mvnrepository.com/artifact/org.kohsuke/github-api)
|
||||||
|
[](https://gitter.im/github-api/github-api?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
|
||||||
|
|
||||||
|
See https://github-api.kohsuke.org/ for more details
|
||||||
430
pom.xml
430
pom.xml
@@ -3,58 +3,151 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.kohsuke</groupId>
|
<groupId>org.kohsuke</groupId>
|
||||||
<artifactId>pom</artifactId>
|
<artifactId>pom</artifactId>
|
||||||
<version>20</version>
|
<version>21</version>
|
||||||
|
<relativePath />
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.95</version>
|
<version>1.101</version>
|
||||||
<name>GitHub API for Java</name>
|
<name>GitHub API for Java</name>
|
||||||
<url>http://github-api.kohsuke.org/</url>
|
<url>https://github-api.kohsuke.org/</url>
|
||||||
<description>GitHub API for Java</description>
|
<description>GitHub API for Java</description>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
<connection>scm:git:git@github.com/github-api/${project.artifactId}.git</connection>
|
||||||
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
<developerConnection>scm:git:ssh://git@github.com/github-api/${project.artifactId}.git</developerConnection>
|
||||||
<url>http://${project.artifactId}.kohsuke.org/</url>
|
<url>https://${project.artifactId}.kohsuke.org/</url>
|
||||||
<tag>github-api-1.95</tag>
|
<tag>github-api-1.101</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<site>
|
<site>
|
||||||
<id>github-pages</id>
|
<id>github-pages</id>
|
||||||
<url>gitsite:git@github.com/kohsuke/${project.artifactId}.git</url>
|
<url>gitsite:git@github.com/github-api/${project.artifactId}.git</url>
|
||||||
</site>
|
</site>
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<findbugs-maven-plugin.version>3.0.2</findbugs-maven-plugin.version>
|
<spotbugs-maven-plugin.version>3.1.12.2</spotbugs-maven-plugin.version>
|
||||||
<findbugs-maven-plugin.failOnError>true</findbugs-maven-plugin.failOnError>
|
<spotbugs.version>3.1.12</spotbugs.version>
|
||||||
|
<spotbugs-maven-plugin.failOnError>true</spotbugs-maven-plugin.failOnError>
|
||||||
|
<hamcrest.version>2.2</hamcrest.version>
|
||||||
|
<okhttp3.version>4.2.2</okhttp3.version>
|
||||||
|
<okio.version>2.4.1</okio.version>
|
||||||
|
<formatter-maven-plugin.goal>format</formatter-maven-plugin.goal>
|
||||||
|
<impsort-maven-plugin.goal>sort</impsort-maven-plugin.goal>
|
||||||
|
<jacoco.coverage.target.class>.80</jacoco.coverage.target.class>
|
||||||
|
<jacoco.coverage.target.method>0.20</jacoco.coverage.target.method>
|
||||||
|
<jacoco.coverage.target.line>0.50</jacoco.coverage.target.line>
|
||||||
|
<jacoco.coverage.target.other>0.50</jacoco.coverage.target.other>
|
||||||
|
<!-- For non-ci builds we'd like the build to still complete if jacoco metrics aren't met. -->
|
||||||
|
<jacoco.haltOnFailure>false</jacoco.haltOnFailure>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<extensions>
|
||||||
|
<extension>
|
||||||
|
<groupId>org.apache.maven.scm</groupId>
|
||||||
|
<artifactId>maven-scm-provider-gitexe</artifactId>
|
||||||
|
<version>1.11.2</version>
|
||||||
|
</extension>
|
||||||
|
<extension>
|
||||||
|
<groupId>org.apache.maven.scm</groupId>
|
||||||
|
<artifactId>maven-scm-manager-plexus</artifactId>
|
||||||
|
<version>1.11.2</version>
|
||||||
|
</extension>
|
||||||
|
</extensions>
|
||||||
|
<testResources>
|
||||||
|
<testResource>
|
||||||
|
<directory>src/test/resources</directory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/wiremock/**</exclude>
|
||||||
|
</excludes>
|
||||||
|
</testResource>
|
||||||
|
</testResources>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<!-- adds jacoco coverage -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
|
<version>0.8.5</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>3.1.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>8</source>
|
||||||
|
<failOnWarnings>true</failOnWarnings>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<version>2.22.1</version>
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
<version>3.8.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-release-plugin</artifactId>
|
||||||
|
<version>2.5.3</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<rerunFailingTestsCount>2</rerunFailingTestsCount>
|
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||||
|
<useReleaseProfile>false</useReleaseProfile>
|
||||||
|
<releaseProfiles>release</releaseProfiles>
|
||||||
|
<goals>deploy</goals>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.bcel</groupId>
|
||||||
|
<artifactId>bcel</artifactId>
|
||||||
|
<version>6.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<annotationProcessorPath>
|
||||||
|
<groupId>org.jenkins-ci</groupId>
|
||||||
|
<artifactId>annotation-indexer</artifactId>
|
||||||
|
<version>1.12</version>
|
||||||
|
</annotationProcessorPath>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.2</version>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>animal-sniffer-maven-plugin</artifactId>
|
<artifactId>animal-sniffer-maven-plugin</artifactId>
|
||||||
<version>1.15</version>
|
<version>1.18</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<signature>
|
<signature>
|
||||||
<groupId>org.codehaus.mojo.signature</groupId>
|
<groupId>org.codehaus.mojo.signature</groupId>
|
||||||
<artifactId>java15</artifactId>
|
<artifactId>java18</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
</signature>
|
</signature>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>ensure-java-1.5-class-library</id>
|
<id>ensure-java-1.8-class-library</id>
|
||||||
<phase>test</phase>
|
<phase>test</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>check</goal>
|
<goal>check</goal>
|
||||||
@@ -75,19 +168,70 @@
|
|||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>net.revelc.code.formatter</groupId>
|
||||||
<artifactId>findbugs-maven-plugin</artifactId>
|
<artifactId>formatter-maven-plugin</artifactId>
|
||||||
<version>${findbugs-maven-plugin.version}</version>
|
<version>2.11.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>${formatter-maven-plugin.goal}</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<configFile>src/main/resources/eclipse/formatter.xml</configFile>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>net.revelc.code</groupId>
|
||||||
|
<artifactId>impsort-maven-plugin</artifactId>
|
||||||
|
<version>1.3.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<xmlOutput>true</xmlOutput>
|
<groups>*,java.,javax.</groups>
|
||||||
<failOnError>${findbugs-maven-plugin.failOnError}</failOnError>
|
<removeUnused>true</removeUnused>
|
||||||
|
<staticAfter>true</staticAfter>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>run-findbugs</id>
|
|
||||||
<phase>verify</phase>
|
|
||||||
<goals>
|
<goals>
|
||||||
<goal>check</goal>
|
<goal>${impsort-maven-plugin.goal}</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.github.spotbugs</groupId>
|
||||||
|
<artifactId>spotbugs-maven-plugin</artifactId>
|
||||||
|
<version>${spotbugs-maven-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<xmlOutput>true</xmlOutput>
|
||||||
|
<failOnError>${spotbugs-maven-plugin.failOnError}</failOnError>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>run-spotbugs</id>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<dependencies>
|
||||||
|
<!-- overwrite dependency on spotbugs if you want to specify the version of spotbugs -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.spotbugs</groupId>
|
||||||
|
<artifactId>spotbugs</artifactId>
|
||||||
|
<version>${spotbugs.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
|
<!-- Do not use gmaven plugin -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.gmaven</groupId>
|
||||||
|
<artifactId>gmaven-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
@@ -99,12 +243,31 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>3.7</version>
|
<version>3.9</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-codec</groupId>
|
<groupId>commons-codec</groupId>
|
||||||
<artifactId>commons-codec</artifactId>
|
<artifactId>commons-codec</artifactId>
|
||||||
<version>1.7</version>
|
<version>1.13</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
<artifactId>hamcrest</artifactId>
|
||||||
|
<version>${hamcrest.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- This is needed in order to force junit4 and JTH tests to use newer hamcrest version -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
<artifactId>hamcrest-core</artifactId>
|
||||||
|
<version>${hamcrest.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
<artifactId>hamcrest-library</artifactId>
|
||||||
|
<version>${hamcrest.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
@@ -112,26 +275,20 @@
|
|||||||
<version>4.12</version>
|
<version>4.12</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-all</artifactId>
|
|
||||||
<version>1.3</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>2.9.2</version>
|
<version>2.10.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>1.4</version>
|
<version>2.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.infradna.tool</groupId>
|
<groupId>com.infradna.tool</groupId>
|
||||||
<artifactId>bridge-method-annotation</artifactId>
|
<artifactId>bridge-method-annotation</artifactId>
|
||||||
<version>1.17</version>
|
<version>1.18</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -143,21 +300,35 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jgit</groupId>
|
<groupId>org.eclipse.jgit</groupId>
|
||||||
<artifactId>org.eclipse.jgit</artifactId>
|
<artifactId>org.eclipse.jgit</artifactId>
|
||||||
<version>4.9.0.201710071750-r</version>
|
<version>5.5.1.201910021850-r</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okio</groupId>
|
||||||
|
<artifactId>okio</artifactId>
|
||||||
|
<version>${okio.version}</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
|
<artifactId>okhttp</artifactId>
|
||||||
|
<version>${okhttp3.version}</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<!-- This is the last version of okhttp3 that support UrlConnection -->
|
||||||
|
<!-- The class using this has been deprecated, this dependency can be remove when that class is. -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
|
<artifactId>okhttp-urlconnection</artifactId>
|
||||||
|
<version>3.12.3</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp</groupId>
|
<groupId>com.squareup.okhttp</groupId>
|
||||||
<artifactId>okhttp-urlconnection</artifactId>
|
<artifactId>okhttp-urlconnection</artifactId>
|
||||||
<version>2.7.5</version>
|
<version>2.7.5</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
|
||||||
<artifactId>okhttp-urlconnection</artifactId>
|
|
||||||
<version>3.9.0</version>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.kohsuke</groupId>
|
<groupId>org.kohsuke</groupId>
|
||||||
<artifactId>wordnet-random-name</artifactId>
|
<artifactId>wordnet-random-name</artifactId>
|
||||||
@@ -166,43 +337,198 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<version>1.10.19</version>
|
<version>3.1.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.findbugs</groupId>
|
<groupId>com.github.spotbugs</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>spotbugs-annotations</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>${spotbugs.version}</version>
|
||||||
<scope>provided</scope>
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.tomakehurst</groupId>
|
||||||
|
<artifactId>wiremock-jre8-standalone</artifactId>
|
||||||
|
<version>2.25.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.8.6</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>repo.jenkins-ci.org</id>
|
<id>repo.jenkins-ci.org</id>
|
||||||
<url>http://repo.jenkins-ci.org/public/</url>
|
<url>https://repo.jenkins-ci.org/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
<pluginRepositories>
|
<pluginRepositories>
|
||||||
<pluginRepository>
|
<pluginRepository>
|
||||||
<id>repo.jenkins-ci.org</id>
|
<id>repo.jenkins-ci.org</id>
|
||||||
<url>http://repo.jenkins-ci.org/public/</url>
|
<url>https://repo.jenkins-ci.org/public/</url>
|
||||||
</pluginRepository>
|
</pluginRepository>
|
||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>ci</id>
|
||||||
|
<properties>
|
||||||
|
<formatter-maven-plugin.goal>validate</formatter-maven-plugin.goal>
|
||||||
|
<impsort-maven-plugin.goal>check</impsort-maven-plugin.goal>
|
||||||
|
</properties>
|
||||||
|
<build>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>jacoco</id>
|
||||||
|
<activation>
|
||||||
|
<property>
|
||||||
|
<name>enable-jacoco</name>
|
||||||
|
</property>
|
||||||
|
</activation>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
|
<version>0.8.5</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>prepare-agent</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<!-- attached to Maven test phase -->
|
||||||
|
<execution>
|
||||||
|
<id>report</id>
|
||||||
|
<phase>test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>report</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>check</id>
|
||||||
|
<phase>install</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<rules>
|
||||||
|
<rule>
|
||||||
|
<!--We end up with chatty logs, but it shows us which particular classes -->
|
||||||
|
<!--are lacking in coverage. If this is too much, just remove the -->
|
||||||
|
<!--<element>CLASS</element> tag below. -->
|
||||||
|
<element>CLASS</element>
|
||||||
|
<limits>
|
||||||
|
<!-- These limits can be overridden, in the form of `0.50` for -->
|
||||||
|
<!-- 50%, as necessary. Using a property just puts it in one spot. -->
|
||||||
|
<!--
|
||||||
|
<limit>
|
||||||
|
<counter>LINE</counter>
|
||||||
|
<value>COVEREDRATIO</value>
|
||||||
|
<minimum>${jacoco.coverage.target.lines}</minimum>
|
||||||
|
</limit>
|
||||||
|
-->
|
||||||
|
<!--
|
||||||
|
<limit>
|
||||||
|
<counter>BRANCH</counter>
|
||||||
|
<value>COVEREDRATIO</value>
|
||||||
|
<minimum>${jacoco.coverage.target.other}</minimum>
|
||||||
|
</limit>
|
||||||
|
-->
|
||||||
|
<!--
|
||||||
|
<limit>
|
||||||
|
<counter>INSTRUCTION</counter>
|
||||||
|
<value>COVEREDRATIO</value>
|
||||||
|
<minimum>${jacoco.coverage.target.other}</minimum>
|
||||||
|
</limit>
|
||||||
|
-->
|
||||||
|
<!--
|
||||||
|
<limit>
|
||||||
|
<counter>COMPLEXITY</counter>
|
||||||
|
<value>COVEREDRATIO</value>
|
||||||
|
<minimum>${jacoco.coverage.target.other}</minimum>
|
||||||
|
</limit>
|
||||||
|
-->
|
||||||
|
<limit>
|
||||||
|
<counter>METHOD</counter>
|
||||||
|
<value>COVEREDRATIO</value>
|
||||||
|
<minimum>${jacoco.coverage.target.method}</minimum>
|
||||||
|
</limit>
|
||||||
|
<!-- <limit>-->
|
||||||
|
<!-- <counter>CLASS</counter>-->
|
||||||
|
<!-- <value>COVEREDRATIO</value>-->
|
||||||
|
<!-- <minimum>${jacoco.coverage.target.class}</minimum>-->
|
||||||
|
<!-- </limit>-->
|
||||||
|
</limits>
|
||||||
|
<excludes>
|
||||||
|
<exclude>org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory.**</exclude>
|
||||||
|
<exclude>org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory</exclude>
|
||||||
|
<exclude>org.kohsuke.github.extras.OkHttp3Connector</exclude>
|
||||||
|
<!--<exclude>io.jenkins.plugins.todeclarative.converter.api.*</exclude>-->
|
||||||
|
</excludes>
|
||||||
|
</rule>
|
||||||
|
</rules>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>release</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
|
<version>1.6</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>sign-artifacts</id>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>sign</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<gpgArguments>
|
||||||
|
<arg>--pinentry-mode</arg>
|
||||||
|
<arg>loopback</arg>
|
||||||
|
</gpgArguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
<reporting>
|
<reporting>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</reporting>
|
</reporting>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
<name>The MIT license</name>
|
<name>The MIT license</name>
|
||||||
<url>http://www.opensource.org/licenses/mit-license.php</url>
|
<url>https://www.opensource.org/licenses/mit-license.php</url>
|
||||||
<distribution>repo</distribution>
|
<distribution>repo</distribution>
|
||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.net.HttpURLConnection;
|
|||||||
* Pluggable strategy to determine what to do when the API abuse limit is hit.
|
* Pluggable strategy to determine what to do when the API abuse limit is hit.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GitHubBuilder#withAbuseLimitHandler(AbuseLimitHandler)
|
* @see GitHubBuilder#withAbuseLimitHandler(AbuseLimitHandler) GitHubBuilder#withAbuseLimitHandler(AbuseLimitHandler)
|
||||||
* @see <a href="https://developer.github.com/v3/#abuse-rate-limits">documentation</a>
|
* @see <a href="https://developer.github.com/v3/#abuse-rate-limits">documentation</a>
|
||||||
* @see RateLimitHandler
|
* @see RateLimitHandler
|
||||||
*/
|
*/
|
||||||
@@ -17,16 +17,18 @@ public abstract class AbuseLimitHandler {
|
|||||||
* Called when the library encounters HTTP error indicating that the API abuse limit is reached.
|
* Called when the library encounters HTTP error indicating that the API abuse limit is reached.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Any exception thrown from this method will cause the request to fail, and the caller of github-api
|
* Any exception thrown from this method will cause the request to fail, and the caller of github-api will receive
|
||||||
* will receive an exception. If this method returns normally, another request will be attempted.
|
* an exception. If this method returns normally, another request will be attempted. For that to make sense, the
|
||||||
* For that to make sense, the implementation needs to wait for some time.
|
* implementation needs to wait for some time.
|
||||||
*
|
*
|
||||||
* @see <a href="https://developer.github.com/v3/#abuse-rate-limits">API documentation from GitHub</a>
|
|
||||||
* @param e
|
* @param e
|
||||||
* Exception from Java I/O layer. If you decide to fail the processing, you can throw
|
* Exception from Java I/O layer. If you decide to fail the processing, you can throw this exception (or
|
||||||
* this exception (or wrap this exception into another exception and throw it.)
|
* wrap this exception into another exception and throw it).
|
||||||
* @param uc
|
* @param uc
|
||||||
* Connection that resulted in an error. Useful for accessing other response headers.
|
* Connection that resulted in an error. Useful for accessing other response headers.
|
||||||
|
* @throws IOException
|
||||||
|
* on failure
|
||||||
|
* @see <a href="https://developer.github.com/v3/#abuse-rate-limits">API documentation from GitHub</a>
|
||||||
*/
|
*/
|
||||||
public abstract void onError(IOException e, HttpURLConnection uc) throws IOException;
|
public abstract void onError(IOException e, HttpURLConnection uc) throws IOException;
|
||||||
|
|
||||||
@@ -38,16 +40,17 @@ public abstract class AbuseLimitHandler {
|
|||||||
public void onError(IOException e, HttpURLConnection uc) throws IOException {
|
public void onError(IOException e, HttpURLConnection uc) throws IOException {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(parseWaitTime(uc));
|
Thread.sleep(parseWaitTime(uc));
|
||||||
} catch (InterruptedException _) {
|
} catch (InterruptedException ex) {
|
||||||
throw (InterruptedIOException)new InterruptedIOException().initCause(e);
|
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long parseWaitTime(HttpURLConnection uc) {
|
private long parseWaitTime(HttpURLConnection uc) {
|
||||||
String v = uc.getHeaderField("Retry-After");
|
String v = uc.getHeaderField("Retry-After");
|
||||||
if (v==null) return 60 * 1000; // can't tell, return 1 min
|
if (v == null)
|
||||||
|
return 60 * 1000; // can't tell, return 1 min
|
||||||
|
|
||||||
return Math.max(1000, Long.parseLong(v)*1000);
|
return Math.max(1000, Long.parseLong(v) * 1000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -57,7 +60,7 @@ public abstract class AbuseLimitHandler {
|
|||||||
public static final AbuseLimitHandler FAIL = new AbuseLimitHandler() {
|
public static final AbuseLimitHandler FAIL = new AbuseLimitHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onError(IOException e, HttpURLConnection uc) throws IOException {
|
public void onError(IOException e, HttpURLConnection uc) throws IOException {
|
||||||
throw (IOException)new IOException("Abust limit reached").initCause(e);
|
throw (IOException) new IOException("Abuse limit reached").initCause(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|||||||
/**
|
/**
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD",
|
@SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD",
|
||||||
justification = "Being constructed by JSON deserialization")
|
justification = "Being constructed by JSON deserialization")
|
||||||
class DeleteToken {
|
class DeleteToken {
|
||||||
public String delete_token;
|
public String delete_token;
|
||||||
|
|||||||
274
src/main/java/org/kohsuke/github/GHApp.java
Normal file
274
src/main/java/org/kohsuke/github/GHApp.java
Normal file
@@ -0,0 +1,274 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.kohsuke.github.Previews.MACHINE_MAN;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Github App.
|
||||||
|
*
|
||||||
|
* @author Paulo Miguel Almeida
|
||||||
|
* @see GitHub#getApp() GitHub#getApp()
|
||||||
|
*/
|
||||||
|
public class GHApp extends GHObject {
|
||||||
|
|
||||||
|
private GitHub root;
|
||||||
|
private GHUser owner;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private String externalUrl;
|
||||||
|
private Map<String, String> permissions;
|
||||||
|
private List<GHEvent> events;
|
||||||
|
private long installationsCount;
|
||||||
|
private String htmlUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets owner.
|
||||||
|
*
|
||||||
|
* @return the owner
|
||||||
|
*/
|
||||||
|
public GHUser getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets owner.
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
* the owner
|
||||||
|
*/
|
||||||
|
public void setOwner(GHUser owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets name.
|
||||||
|
*
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets name.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets description.
|
||||||
|
*
|
||||||
|
* @return the description
|
||||||
|
*/
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets description.
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
* the description
|
||||||
|
*/
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets external url.
|
||||||
|
*
|
||||||
|
* @return the external url
|
||||||
|
*/
|
||||||
|
public String getExternalUrl() {
|
||||||
|
return externalUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets external url.
|
||||||
|
*
|
||||||
|
* @param externalUrl
|
||||||
|
* the external url
|
||||||
|
*/
|
||||||
|
public void setExternalUrl(String externalUrl) {
|
||||||
|
this.externalUrl = externalUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets events.
|
||||||
|
*
|
||||||
|
* @return the events
|
||||||
|
*/
|
||||||
|
public List<GHEvent> getEvents() {
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets events.
|
||||||
|
*
|
||||||
|
* @param events
|
||||||
|
* the events
|
||||||
|
*/
|
||||||
|
public void setEvents(List<GHEvent> events) {
|
||||||
|
this.events = events;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets installations count.
|
||||||
|
*
|
||||||
|
* @return the installations count
|
||||||
|
*/
|
||||||
|
public long getInstallationsCount() {
|
||||||
|
return installationsCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets installations count.
|
||||||
|
*
|
||||||
|
* @param installationsCount
|
||||||
|
* the installations count
|
||||||
|
*/
|
||||||
|
public void setInstallationsCount(long installationsCount) {
|
||||||
|
this.installationsCount = installationsCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getHtmlUrl() {
|
||||||
|
return GitHub.parseURL(htmlUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets permissions.
|
||||||
|
*
|
||||||
|
* @return the permissions
|
||||||
|
*/
|
||||||
|
public Map<String, String> getPermissions() {
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets permissions.
|
||||||
|
*
|
||||||
|
* @param permissions
|
||||||
|
* the permissions
|
||||||
|
*/
|
||||||
|
public void setPermissions(Map<String, String> permissions) {
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
GHApp wrapUp(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains all the installations associated with this app.
|
||||||
|
* <p>
|
||||||
|
* You must use a JWT to access this endpoint.
|
||||||
|
*
|
||||||
|
* @return a list of App installations
|
||||||
|
* @see <a href="https://developer.github.com/v3/apps/#list-installations">List installations</a>
|
||||||
|
*/
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
|
public PagedIterable<GHAppInstallation> listInstallations() {
|
||||||
|
return root.retrieve()
|
||||||
|
.withPreview(MACHINE_MAN)
|
||||||
|
.asPagedIterable("/app/installations", GHAppInstallation[].class, item -> item.wrapUp(root));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain an installation associated with this app.
|
||||||
|
* <p>
|
||||||
|
* You must use a JWT to access this endpoint.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* Installation Id
|
||||||
|
* @return a GHAppInstallation
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
|
* @see <a href="https://developer.github.com/v3/apps/#get-an-installation">Get an installation</a>
|
||||||
|
*/
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
|
public GHAppInstallation getInstallationById(long id) throws IOException {
|
||||||
|
return root.retrieve()
|
||||||
|
.withPreview(MACHINE_MAN)
|
||||||
|
.to(String.format("/app/installations/%d", id), GHAppInstallation.class)
|
||||||
|
.wrapUp(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain an organization installation associated with this app.
|
||||||
|
* <p>
|
||||||
|
* You must use a JWT to access this endpoint.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* Organization name
|
||||||
|
* @return a GHAppInstallation
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
|
* @see <a href="https://developer.github.com/v3/apps/#get-an-organization-installation">Get an organization
|
||||||
|
* installation</a>
|
||||||
|
*/
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
|
public GHAppInstallation getInstallationByOrganization(String name) throws IOException {
|
||||||
|
return root.retrieve()
|
||||||
|
.withPreview(MACHINE_MAN)
|
||||||
|
.to(String.format("/orgs/%s/installation", name), GHAppInstallation.class)
|
||||||
|
.wrapUp(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain an repository installation associated with this app.
|
||||||
|
* <p>
|
||||||
|
* You must use a JWT to access this endpoint.
|
||||||
|
*
|
||||||
|
* @param ownerName
|
||||||
|
* Organization or user name
|
||||||
|
* @param repositoryName
|
||||||
|
* Repository name
|
||||||
|
* @return a GHAppInstallation
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
|
* @see <a href="https://developer.github.com/v3/apps/#get-a-repository-installation">Get a repository
|
||||||
|
* installation</a>
|
||||||
|
*/
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
|
public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) throws IOException {
|
||||||
|
return root.retrieve()
|
||||||
|
.withPreview(MACHINE_MAN)
|
||||||
|
.to(String.format("/repos/%s/%s/installation", ownerName, repositoryName), GHAppInstallation.class)
|
||||||
|
.wrapUp(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain a user installation associated with this app.
|
||||||
|
* <p>
|
||||||
|
* You must use a JWT to access this endpoint.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* user name
|
||||||
|
* @return a GHAppInstallation
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
|
* @see <a href="https://developer.github.com/v3/apps/#get-a-user-installation">Get a user installation</a>
|
||||||
|
*/
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
|
public GHAppInstallation getInstallationByUser(String name) throws IOException {
|
||||||
|
return root.retrieve()
|
||||||
|
.withPreview(MACHINE_MAN)
|
||||||
|
.to(String.format("/users/%s/installation", name), GHAppInstallation.class)
|
||||||
|
.wrapUp(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.kohsuke.github.Previews.MACHINE_MAN;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a access token for a GitHub App Installation
|
||||||
|
*
|
||||||
|
* @author Paulo Miguel Almeida
|
||||||
|
* @see GHAppInstallation#createToken(Map) GHAppInstallation#createToken(Map)
|
||||||
|
*/
|
||||||
|
public class GHAppCreateTokenBuilder {
|
||||||
|
private final GitHub root;
|
||||||
|
protected final Requester builder;
|
||||||
|
private final String apiUrlTail;
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
|
GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map<String, GHPermissionType> permissions) {
|
||||||
|
this.root = root;
|
||||||
|
this.apiUrlTail = apiUrlTail;
|
||||||
|
this.builder = new Requester(root);
|
||||||
|
withPermissions(builder, permissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default the installation token has access to all repositories that the installation can access. To restrict
|
||||||
|
* the access to specific repositories, you can provide the repository_ids when creating the token. When you omit
|
||||||
|
* repository_ids, the response does not contain neither the repositories nor the permissions key.
|
||||||
|
*
|
||||||
|
* @param repositoryIds
|
||||||
|
* Array containing the repositories Ids
|
||||||
|
* @return a GHAppCreateTokenBuilder
|
||||||
|
*/
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
|
public GHAppCreateTokenBuilder repositoryIds(List<Long> repositoryIds) {
|
||||||
|
this.builder.with("repository_ids", repositoryIds);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an app token with all the parameters.
|
||||||
|
* <p>
|
||||||
|
* You must use a JWT to access this endpoint.
|
||||||
|
*
|
||||||
|
* @return a GHAppInstallationToken
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
|
*/
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
|
public GHAppInstallationToken create() throws IOException {
|
||||||
|
return builder.method("POST")
|
||||||
|
.withPreview(MACHINE_MAN)
|
||||||
|
.to(apiUrlTail, GHAppInstallationToken.class)
|
||||||
|
.wrapUp(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Requester withPermissions(Requester builder, Map<String, GHPermissionType> value) {
|
||||||
|
Map<String, String> retMap = new HashMap<String, String>();
|
||||||
|
for (Map.Entry<String, GHPermissionType> entry : value.entrySet()) {
|
||||||
|
retMap.put(entry.getKey(), Requester.transformEnum(entry.getValue()));
|
||||||
|
}
|
||||||
|
return builder.with("permissions", retMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
293
src/main/java/org/kohsuke/github/GHAppInstallation.java
Normal file
293
src/main/java/org/kohsuke/github/GHAppInstallation.java
Normal file
@@ -0,0 +1,293 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.kohsuke.github.Previews.GAMBIT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Github App Installation.
|
||||||
|
*
|
||||||
|
* @author Paulo Miguel Almeida
|
||||||
|
* @see GHApp#listInstallations() GHApp#listInstallations()
|
||||||
|
* @see GHApp#getInstallationById(long) GHApp#getInstallationById(long)
|
||||||
|
* @see GHApp#getInstallationByOrganization(String) GHApp#getInstallationByOrganization(String)
|
||||||
|
* @see GHApp#getInstallationByRepository(String, String) GHApp#getInstallationByRepository(String, String)
|
||||||
|
* @see GHApp#getInstallationByUser(String) GHApp#getInstallationByUser(String)
|
||||||
|
*/
|
||||||
|
public class GHAppInstallation extends GHObject {
|
||||||
|
private GitHub root;
|
||||||
|
private GHUser account;
|
||||||
|
|
||||||
|
@JsonProperty("access_tokens_url")
|
||||||
|
private String accessTokenUrl;
|
||||||
|
@JsonProperty("repositories_url")
|
||||||
|
private String repositoriesUrl;
|
||||||
|
@JsonProperty("app_id")
|
||||||
|
private long appId;
|
||||||
|
@JsonProperty("target_id")
|
||||||
|
private long targetId;
|
||||||
|
@JsonProperty("target_type")
|
||||||
|
private GHTargetType targetType;
|
||||||
|
private Map<String, GHPermissionType> permissions;
|
||||||
|
private List<GHEvent> events;
|
||||||
|
@JsonProperty("single_file_name")
|
||||||
|
private String singleFileName;
|
||||||
|
@JsonProperty("repository_selection")
|
||||||
|
private GHRepositorySelection repositorySelection;
|
||||||
|
private String htmlUrl;
|
||||||
|
|
||||||
|
public URL getHtmlUrl() {
|
||||||
|
return GitHub.parseURL(htmlUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets root.
|
||||||
|
*
|
||||||
|
* @return the root
|
||||||
|
*/
|
||||||
|
public GitHub getRoot() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets root.
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* the root
|
||||||
|
*/
|
||||||
|
public void setRoot(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets account.
|
||||||
|
*
|
||||||
|
* @return the account
|
||||||
|
*/
|
||||||
|
public GHUser getAccount() {
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets account.
|
||||||
|
*
|
||||||
|
* @param account
|
||||||
|
* the account
|
||||||
|
*/
|
||||||
|
public void setAccount(GHUser account) {
|
||||||
|
this.account = account;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets access token url.
|
||||||
|
*
|
||||||
|
* @return the access token url
|
||||||
|
*/
|
||||||
|
public String getAccessTokenUrl() {
|
||||||
|
return accessTokenUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets access token url.
|
||||||
|
*
|
||||||
|
* @param accessTokenUrl
|
||||||
|
* the access token url
|
||||||
|
*/
|
||||||
|
public void setAccessTokenUrl(String accessTokenUrl) {
|
||||||
|
this.accessTokenUrl = accessTokenUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets repositories url.
|
||||||
|
*
|
||||||
|
* @return the repositories url
|
||||||
|
*/
|
||||||
|
public String getRepositoriesUrl() {
|
||||||
|
return repositoriesUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets repositories url.
|
||||||
|
*
|
||||||
|
* @param repositoriesUrl
|
||||||
|
* the repositories url
|
||||||
|
*/
|
||||||
|
public void setRepositoriesUrl(String repositoriesUrl) {
|
||||||
|
this.repositoriesUrl = repositoriesUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets app id.
|
||||||
|
*
|
||||||
|
* @return the app id
|
||||||
|
*/
|
||||||
|
public long getAppId() {
|
||||||
|
return appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets app id.
|
||||||
|
*
|
||||||
|
* @param appId
|
||||||
|
* the app id
|
||||||
|
*/
|
||||||
|
public void setAppId(long appId) {
|
||||||
|
this.appId = appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets target id.
|
||||||
|
*
|
||||||
|
* @return the target id
|
||||||
|
*/
|
||||||
|
public long getTargetId() {
|
||||||
|
return targetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets target id.
|
||||||
|
*
|
||||||
|
* @param targetId
|
||||||
|
* the target id
|
||||||
|
*/
|
||||||
|
public void setTargetId(long targetId) {
|
||||||
|
this.targetId = targetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets target type.
|
||||||
|
*
|
||||||
|
* @return the target type
|
||||||
|
*/
|
||||||
|
public GHTargetType getTargetType() {
|
||||||
|
return targetType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets target type.
|
||||||
|
*
|
||||||
|
* @param targetType
|
||||||
|
* the target type
|
||||||
|
*/
|
||||||
|
public void setTargetType(GHTargetType targetType) {
|
||||||
|
this.targetType = targetType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets permissions.
|
||||||
|
*
|
||||||
|
* @return the permissions
|
||||||
|
*/
|
||||||
|
public Map<String, GHPermissionType> getPermissions() {
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets permissions.
|
||||||
|
*
|
||||||
|
* @param permissions
|
||||||
|
* the permissions
|
||||||
|
*/
|
||||||
|
public void setPermissions(Map<String, GHPermissionType> permissions) {
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets events.
|
||||||
|
*
|
||||||
|
* @return the events
|
||||||
|
*/
|
||||||
|
public List<GHEvent> getEvents() {
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets events.
|
||||||
|
*
|
||||||
|
* @param events
|
||||||
|
* the events
|
||||||
|
*/
|
||||||
|
public void setEvents(List<GHEvent> events) {
|
||||||
|
this.events = events;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets single file name.
|
||||||
|
*
|
||||||
|
* @return the single file name
|
||||||
|
*/
|
||||||
|
public String getSingleFileName() {
|
||||||
|
return singleFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets single file name.
|
||||||
|
*
|
||||||
|
* @param singleFileName
|
||||||
|
* the single file name
|
||||||
|
*/
|
||||||
|
public void setSingleFileName(String singleFileName) {
|
||||||
|
this.singleFileName = singleFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets repository selection.
|
||||||
|
*
|
||||||
|
* @return the repository selection
|
||||||
|
*/
|
||||||
|
public GHRepositorySelection getRepositorySelection() {
|
||||||
|
return repositorySelection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets repository selection.
|
||||||
|
*
|
||||||
|
* @param repositorySelection
|
||||||
|
* the repository selection
|
||||||
|
*/
|
||||||
|
public void setRepositorySelection(GHRepositorySelection repositorySelection) {
|
||||||
|
this.repositorySelection = repositorySelection;
|
||||||
|
}
|
||||||
|
|
||||||
|
GHAppInstallation wrapUp(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a Github App installation
|
||||||
|
* <p>
|
||||||
|
* You must use a JWT to access this endpoint.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
|
* @see <a href="https://developer.github.com/v3/apps/#delete-an-installation">Delete an installation</a>
|
||||||
|
*/
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
|
public void deleteInstallation() throws IOException {
|
||||||
|
root.retrieve().method("DELETE").withPreview(GAMBIT).to(String.format("/app/installations/%d", id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a builder that creates a new App Installation Token.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* You use the returned builder to set various properties, then call {@link GHAppCreateTokenBuilder#create()} to
|
||||||
|
* finally create an access token.
|
||||||
|
*
|
||||||
|
* @param permissions
|
||||||
|
* map of permissions for the created token
|
||||||
|
* @return a GHAppCreateTokenBuilder on error
|
||||||
|
*/
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
|
public GHAppCreateTokenBuilder createToken(Map<String, GHPermissionType> permissions) {
|
||||||
|
return new GHAppCreateTokenBuilder(root, String.format("/app/installations/%d/access_tokens", id), permissions);
|
||||||
|
}
|
||||||
|
}
|
||||||
142
src/main/java/org/kohsuke/github/GHAppInstallationToken.java
Normal file
142
src/main/java/org/kohsuke/github/GHAppInstallationToken.java
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||||
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Github App Installation Token.
|
||||||
|
*
|
||||||
|
* @author Paulo Miguel Almeida
|
||||||
|
* @see GHAppInstallation#createToken(Map) GHAppInstallation#createToken(Map)
|
||||||
|
*/
|
||||||
|
public class GHAppInstallationToken {
|
||||||
|
private GitHub root;
|
||||||
|
|
||||||
|
private String token;
|
||||||
|
protected String expires_at;
|
||||||
|
private Map<String, String> permissions;
|
||||||
|
private List<GHRepository> repositories;
|
||||||
|
private GHRepositorySelection repositorySelection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets root.
|
||||||
|
*
|
||||||
|
* @return the root
|
||||||
|
*/
|
||||||
|
public GitHub getRoot() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets root.
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* the root
|
||||||
|
*/
|
||||||
|
public void setRoot(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets permissions.
|
||||||
|
*
|
||||||
|
* @return the permissions
|
||||||
|
*/
|
||||||
|
public Map<String, String> getPermissions() {
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets permissions.
|
||||||
|
*
|
||||||
|
* @param permissions
|
||||||
|
* the permissions
|
||||||
|
*/
|
||||||
|
public void setPermissions(Map<String, String> permissions) {
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets token.
|
||||||
|
*
|
||||||
|
* @return the token
|
||||||
|
*/
|
||||||
|
public String getToken() {
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets token.
|
||||||
|
*
|
||||||
|
* @param token
|
||||||
|
* the token
|
||||||
|
*/
|
||||||
|
public void setToken(String token) {
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets repositories.
|
||||||
|
*
|
||||||
|
* @return the repositories
|
||||||
|
*/
|
||||||
|
public List<GHRepository> getRepositories() {
|
||||||
|
return repositories;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets repositories.
|
||||||
|
*
|
||||||
|
* @param repositories
|
||||||
|
* the repositories
|
||||||
|
*/
|
||||||
|
public void setRepositories(List<GHRepository> repositories) {
|
||||||
|
this.repositories = repositories;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets repository selection.
|
||||||
|
*
|
||||||
|
* @return the repository selection
|
||||||
|
*/
|
||||||
|
public GHRepositorySelection getRepositorySelection() {
|
||||||
|
return repositorySelection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets repository selection.
|
||||||
|
*
|
||||||
|
* @param repositorySelection
|
||||||
|
* the repository selection
|
||||||
|
*/
|
||||||
|
public void setRepositorySelection(GHRepositorySelection repositorySelection) {
|
||||||
|
this.repositorySelection = repositorySelection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets expires at.
|
||||||
|
*
|
||||||
|
* @return date when this token expires
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
|
*/
|
||||||
|
@WithBridgeMethods(value = String.class, adapterMethod = "expiresAtStr")
|
||||||
|
public Date getExpiresAt() throws IOException {
|
||||||
|
return GitHub.parseDate(expires_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getExpiresAt")
|
||||||
|
private Object expiresAtStr(Date id, Class type) {
|
||||||
|
return expires_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
GHAppInstallationToken wrapUp(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ import java.net.URL;
|
|||||||
/**
|
/**
|
||||||
* Asset in a release.
|
* Asset in a release.
|
||||||
*
|
*
|
||||||
* @see GHRelease#getAssets()
|
* @see GHRelease#getAssets() GHRelease#getAssets()
|
||||||
*/
|
*/
|
||||||
public class GHAsset extends GHObject {
|
public class GHAsset extends GHObject {
|
||||||
GitHub root;
|
GitHub root;
|
||||||
@@ -19,44 +19,100 @@ public class GHAsset extends GHObject {
|
|||||||
private long download_count;
|
private long download_count;
|
||||||
private String browser_download_url;
|
private String browser_download_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets content type.
|
||||||
|
*
|
||||||
|
* @return the content type
|
||||||
|
*/
|
||||||
public String getContentType() {
|
public String getContentType() {
|
||||||
return content_type;
|
return content_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets content type.
|
||||||
|
*
|
||||||
|
* @param contentType
|
||||||
|
* the content type
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void setContentType(String contentType) throws IOException {
|
public void setContentType(String contentType) throws IOException {
|
||||||
edit("content_type", contentType);
|
edit("content_type", contentType);
|
||||||
this.content_type = contentType;
|
this.content_type = contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets download count.
|
||||||
|
*
|
||||||
|
* @return the download count
|
||||||
|
*/
|
||||||
public long getDownloadCount() {
|
public long getDownloadCount() {
|
||||||
return download_count;
|
return download_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets label.
|
||||||
|
*
|
||||||
|
* @return the label
|
||||||
|
*/
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets label.
|
||||||
|
*
|
||||||
|
* @param label
|
||||||
|
* the label
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void setLabel(String label) throws IOException {
|
public void setLabel(String label) throws IOException {
|
||||||
edit("label", label);
|
edit("label", label);
|
||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets name.
|
||||||
|
*
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets owner.
|
||||||
|
*
|
||||||
|
* @return the owner
|
||||||
|
*/
|
||||||
public GHRepository getOwner() {
|
public GHRepository getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets root.
|
||||||
|
*
|
||||||
|
* @return the root
|
||||||
|
*/
|
||||||
public GitHub getRoot() {
|
public GitHub getRoot() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets size.
|
||||||
|
*
|
||||||
|
* @return the size
|
||||||
|
*/
|
||||||
public long getSize() {
|
public long getSize() {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets state.
|
||||||
|
*
|
||||||
|
* @return the state
|
||||||
|
*/
|
||||||
public String getState() {
|
public String getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@@ -69,19 +125,29 @@ public class GHAsset extends GHObject {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets browser download url.
|
||||||
|
*
|
||||||
|
* @return the browser download url
|
||||||
|
*/
|
||||||
public String getBrowserDownloadUrl() {
|
public String getBrowserDownloadUrl() {
|
||||||
return browser_download_url;
|
return browser_download_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void edit(String key, Object value) throws IOException {
|
private void edit(String key, Object value) throws IOException {
|
||||||
new Requester(root)._with(key, value).method("PATCH").to(getApiRoute());
|
new Requester(root).with(key, value).method("PATCH").to(getApiRoute());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(root).method("DELETE").to(getApiRoute());
|
new Requester(root).method("DELETE").to(getApiRoute());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String getApiRoute() {
|
private String getApiRoute() {
|
||||||
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/releases/assets/" + id;
|
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/releases/assets/" + id;
|
||||||
}
|
}
|
||||||
@@ -92,6 +158,15 @@ public class GHAsset extends GHObject {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap gh asset [ ].
|
||||||
|
*
|
||||||
|
* @param assets
|
||||||
|
* the assets
|
||||||
|
* @param release
|
||||||
|
* the release
|
||||||
|
* @return the gh asset [ ]
|
||||||
|
*/
|
||||||
public static GHAsset[] wrap(GHAsset[] assets, GHRelease release) {
|
public static GHAsset[] wrap(GHAsset[] assets, GHRelease release) {
|
||||||
for (GHAsset aTo : assets) {
|
for (GHAsset aTo : assets) {
|
||||||
aTo.wrap(release);
|
aTo.wrap(release);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import java.util.List;
|
|||||||
* Generated OAuth token
|
* Generated OAuth token
|
||||||
*
|
*
|
||||||
* @author janinko
|
* @author janinko
|
||||||
* @see GitHub#createToken(Collection, String, String)
|
* @see GitHub#createToken(Collection, String, String) GitHub#createToken(Collection, String, String)
|
||||||
* @see <a href="http://developer.github.com/v3/oauth/#create-a-new-authorization">API documentation</a>
|
* @see <a href="http://developer.github.com/v3/oauth/#create-a-new-authorization">API documentation</a>
|
||||||
*/
|
*/
|
||||||
public class GHAuthorization extends GHObject {
|
public class GHAuthorization extends GHObject {
|
||||||
@@ -42,39 +42,78 @@ public class GHAuthorization extends GHObject {
|
|||||||
private String note;
|
private String note;
|
||||||
private String note_url;
|
private String note_url;
|
||||||
private String fingerprint;
|
private String fingerprint;
|
||||||
//TODO add some user class for https://developer.github.com/v3/oauth_authorizations/#check-an-authorization ?
|
// TODO add some user class for https://developer.github.com/v3/oauth_authorizations/#check-an-authorization ?
|
||||||
//private GHUser user;
|
// private GHUser user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets root.
|
||||||
|
*
|
||||||
|
* @return the root
|
||||||
|
*/
|
||||||
public GitHub getRoot() {
|
public GitHub getRoot() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets scopes.
|
||||||
|
*
|
||||||
|
* @return the scopes
|
||||||
|
*/
|
||||||
public List<String> getScopes() {
|
public List<String> getScopes() {
|
||||||
return scopes;
|
return scopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets token.
|
||||||
|
*
|
||||||
|
* @return the token
|
||||||
|
*/
|
||||||
public String getToken() {
|
public String getToken() {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets token last eight.
|
||||||
|
*
|
||||||
|
* @return the token last eight
|
||||||
|
*/
|
||||||
public String getTokenLastEight() {
|
public String getTokenLastEight() {
|
||||||
return token_last_eight;
|
return token_last_eight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets hashed token.
|
||||||
|
*
|
||||||
|
* @return the hashed token
|
||||||
|
*/
|
||||||
public String getHashedToken() {
|
public String getHashedToken() {
|
||||||
return hashed_token;
|
return hashed_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets app url.
|
||||||
|
*
|
||||||
|
* @return the app url
|
||||||
|
*/
|
||||||
public URL getAppUrl() {
|
public URL getAppUrl() {
|
||||||
return GitHub.parseURL(app.url);
|
return GitHub.parseURL(app.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets app name.
|
||||||
|
*
|
||||||
|
* @return the app name
|
||||||
|
*/
|
||||||
public String getAppName() {
|
public String getAppName() {
|
||||||
return app.name;
|
return app.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressFBWarnings(value = "NM_CONFUSING",
|
/**
|
||||||
justification = "It's a part of the library API, cannot be changed")
|
* Gets api url.
|
||||||
|
*
|
||||||
|
* @return the api url
|
||||||
|
*/
|
||||||
|
@SuppressFBWarnings(value = "NM_CONFUSING", justification = "It's a part of the library API, cannot be changed")
|
||||||
public URL getApiURL() {
|
public URL getApiURL() {
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
}
|
}
|
||||||
@@ -87,25 +126,40 @@ public class GHAuthorization extends GHObject {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets note.
|
||||||
|
*
|
||||||
|
* @return the note
|
||||||
|
*/
|
||||||
public String getNote() {
|
public String getNote() {
|
||||||
return note;
|
return note;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets note url.
|
||||||
|
*
|
||||||
|
* @return the note url
|
||||||
|
*/
|
||||||
public URL getNoteUrl() {
|
public URL getNoteUrl() {
|
||||||
return GitHub.parseURL(note_url);
|
return GitHub.parseURL(note_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets fingerprint.
|
||||||
|
*
|
||||||
|
* @return the fingerprint
|
||||||
|
*/
|
||||||
public String getFingerprint() {
|
public String getFingerprint() {
|
||||||
return fingerprint;
|
return fingerprint;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHAuthorization wrap(GitHub root) {
|
GHAuthorization wrap(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD"},
|
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD" },
|
||||||
justification = "JSON API")
|
justification = "JSON API")
|
||||||
private static class App {
|
private static class App {
|
||||||
private String url;
|
private String url;
|
||||||
private String name;
|
private String name;
|
||||||
|
|||||||
@@ -8,10 +8,12 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The type GHBlob.
|
||||||
|
*
|
||||||
* @author Kanstantsin Shautsou
|
* @author Kanstantsin Shautsou
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHTreeEntry#asBlob()
|
* @see GHTreeEntry#asBlob() GHTreeEntry#asBlob()
|
||||||
* @see GHRepository#getBlob(String)
|
* @see GHRepository#getBlob(String) GHRepository#getBlob(String)
|
||||||
* @see <a href="https://developer.github.com/v3/git/blobs/#get-a-blob">Get a blob</a>
|
* @see <a href="https://developer.github.com/v3/git/blobs/#get-a-blob">Get a blob</a>
|
||||||
*/
|
*/
|
||||||
public class GHBlob {
|
public class GHBlob {
|
||||||
@@ -19,46 +21,64 @@ public class GHBlob {
|
|||||||
private long size;
|
private long size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API URL of this blob.
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return API URL of this blob.
|
||||||
*/
|
*/
|
||||||
public URL getUrl() {
|
public URL getUrl() {
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets sha.
|
||||||
|
*
|
||||||
|
* @return the sha
|
||||||
|
*/
|
||||||
public String getSha() {
|
public String getSha() {
|
||||||
return sha;
|
return sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of bytes in this blob.
|
* Gets size.
|
||||||
|
*
|
||||||
|
* @return Number of bytes in this blob.
|
||||||
*/
|
*/
|
||||||
public long getSize() {
|
public long getSize() {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets encoding.
|
||||||
|
*
|
||||||
|
* @return the encoding
|
||||||
|
*/
|
||||||
public String getEncoding() {
|
public String getEncoding() {
|
||||||
return encoding;
|
return encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encoded content. You probably want {@link #read()}
|
* Gets content.
|
||||||
|
*
|
||||||
|
* @return Encoded content. You probably want {@link #read()}
|
||||||
*/
|
*/
|
||||||
public String getContent() {
|
public String getContent() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the actual bytes of the blob.
|
* Read input stream.
|
||||||
|
*
|
||||||
|
* @return the actual bytes of the blob.
|
||||||
*/
|
*/
|
||||||
public InputStream read() {
|
public InputStream read() {
|
||||||
if (encoding.equals("base64")) {
|
if (encoding.equals("base64")) {
|
||||||
try {
|
try {
|
||||||
return new Base64InputStream(new ByteArrayInputStream(content.getBytes("US-ASCII")), false);
|
return new Base64InputStream(new ByteArrayInputStream(content.getBytes("US-ASCII")), false);
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new AssertionError(e); // US-ASCII is mandatory
|
throw new AssertionError(e); // US-ASCII is mandatory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new UnsupportedOperationException("Unrecognized encoding: "+encoding);
|
throw new UnsupportedOperationException("Unrecognized encoding: " + encoding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import org.apache.commons.codec.binary.Base64;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder pattern for creating a new blob.
|
* Builder pattern for creating a new blob. Based on https://developer.github.com/v3/git/blobs/#create-a-blob
|
||||||
* Based on https://developer.github.com/v3/git/blobs/#create-a-blob
|
|
||||||
*/
|
*/
|
||||||
public class GHBlobBuilder {
|
public class GHBlobBuilder {
|
||||||
private final GHRepository repo;
|
private final GHRepository repo;
|
||||||
@@ -19,6 +18,10 @@ public class GHBlobBuilder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures a blob with the specified text {@code content}.
|
* Configures a blob with the specified text {@code content}.
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
* string text of the blob
|
||||||
|
* @return a GHBlobBuilder
|
||||||
*/
|
*/
|
||||||
public GHBlobBuilder textContent(String content) {
|
public GHBlobBuilder textContent(String content) {
|
||||||
req.with("content", content);
|
req.with("content", content);
|
||||||
@@ -28,6 +31,10 @@ public class GHBlobBuilder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures a blob with the specified binary {@code content}.
|
* Configures a blob with the specified binary {@code content}.
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
* byte array of the blob
|
||||||
|
* @return a GHBlobBuilder
|
||||||
*/
|
*/
|
||||||
public GHBlobBuilder binaryContent(byte[] content) {
|
public GHBlobBuilder binaryContent(byte[] content) {
|
||||||
String base64Content = Base64.encodeBase64String(content);
|
String base64Content = Base64.encodeBase64String(content);
|
||||||
@@ -42,6 +49,10 @@ public class GHBlobBuilder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a blob based on the parameters specified thus far.
|
* Creates a blob based on the parameters specified thus far.
|
||||||
|
*
|
||||||
|
* @return a GHBlob
|
||||||
|
* @throws IOException
|
||||||
|
* if the blob cannot be created.
|
||||||
*/
|
*/
|
||||||
public GHBlob create() throws IOException {
|
public GHBlob create() throws IOException {
|
||||||
return req.method("POST").to(getApiTail(), GHBlob.class);
|
return req.method("POST").to(getApiTail(), GHBlob.class);
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static org.kohsuke.github.Previews.*;
|
import static org.kohsuke.github.Previews.*;
|
||||||
|
|
||||||
@@ -14,8 +16,10 @@ import static org.kohsuke.github.Previews.*;
|
|||||||
*
|
*
|
||||||
* @author Yusuke Kokubo
|
* @author Yusuke Kokubo
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
|
@SuppressFBWarnings(
|
||||||
"NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD"}, justification = "JSON API")
|
value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
|
||||||
|
"URF_UNREAD_FIELD" },
|
||||||
|
justification = "JSON API")
|
||||||
public class GHBranch {
|
public class GHBranch {
|
||||||
private GitHub root;
|
private GitHub root;
|
||||||
private GHRepository owner;
|
private GHRepository owner;
|
||||||
@@ -26,7 +30,15 @@ public class GHBranch {
|
|||||||
private boolean protection;
|
private boolean protection;
|
||||||
private String protection_url;
|
private String protection_url;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
GHBranch(@JsonProperty(value = "name", required = true) String name) throws Exception {
|
||||||
|
Objects.requireNonNull(name);
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Commit.
|
||||||
|
*/
|
||||||
public static class Commit {
|
public static class Commit {
|
||||||
String sha;
|
String sha;
|
||||||
|
|
||||||
@@ -34,43 +46,70 @@ public class GHBranch {
|
|||||||
String url;
|
String url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets root.
|
||||||
|
*
|
||||||
|
* @return the root
|
||||||
|
*/
|
||||||
public GitHub getRoot() {
|
public GitHub getRoot() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repository that this branch is in.
|
* Gets owner.
|
||||||
|
*
|
||||||
|
* @return the repository that this branch is in.
|
||||||
*/
|
*/
|
||||||
public GHRepository getOwner() {
|
public GHRepository getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets name.
|
||||||
|
*
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the push to this branch is restricted via branch protection.
|
* Is protected boolean.
|
||||||
|
*
|
||||||
|
* @return true if the push to this branch is restricted via branch protection.
|
||||||
*/
|
*/
|
||||||
@Preview @Deprecated
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public boolean isProtected() {
|
public boolean isProtected() {
|
||||||
return protection;
|
return protection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns API URL that deals with the protection of this branch.
|
* Gets protection url.
|
||||||
|
*
|
||||||
|
* @return API URL that deals with the protection of this branch.
|
||||||
*/
|
*/
|
||||||
@Preview @Deprecated
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public URL getProtectionUrl() {
|
public URL getProtectionUrl() {
|
||||||
return GitHub.parseURL(protection_url);
|
return GitHub.parseURL(protection_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets protection.
|
||||||
|
*
|
||||||
|
* @return the protection
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHBranchProtection getProtection() throws IOException {
|
public GHBranchProtection getProtection() throws IOException {
|
||||||
return root.retrieve().to(protection_url, GHBranchProtection.class).wrap(this);
|
return root.retrieve().to(protection_url, GHBranchProtection.class).wrap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The commit that this branch currently points to.
|
* Gets sha 1.
|
||||||
|
*
|
||||||
|
* @return The SHA1 of the commit that this branch currently points to.
|
||||||
*/
|
*/
|
||||||
public String getSHA1() {
|
public String getSHA1() {
|
||||||
return commit.sha;
|
return commit.sha;
|
||||||
@@ -78,6 +117,9 @@ public class GHBranch {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Disables branch protection and allows anyone with push access to push changes.
|
* Disables branch protection and allows anyone with push access to push changes.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* if disabling protection fails
|
||||||
*/
|
*/
|
||||||
public void disableProtection() throws IOException {
|
public void disableProtection() throws IOException {
|
||||||
new Requester(root).method("DELETE").to(protection_url);
|
new Requester(root).method("DELETE").to(protection_url);
|
||||||
@@ -86,32 +128,43 @@ public class GHBranch {
|
|||||||
/**
|
/**
|
||||||
* Enables branch protection to control what commit statuses are required to push.
|
* Enables branch protection to control what commit statuses are required to push.
|
||||||
*
|
*
|
||||||
* @see GHCommitStatus#getContext()
|
* @return GHBranchProtectionBuilder for enabling protection
|
||||||
|
* @see GHCommitStatus#getContext() GHCommitStatus#getContext()
|
||||||
*/
|
*/
|
||||||
@Preview @Deprecated
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public GHBranchProtectionBuilder enableProtection() {
|
public GHBranchProtectionBuilder enableProtection() {
|
||||||
return new GHBranchProtectionBuilder(this);
|
return new GHBranchProtectionBuilder(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable protection.
|
||||||
|
*
|
||||||
|
* @param level
|
||||||
|
* the level
|
||||||
|
* @param contexts
|
||||||
|
* the contexts
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
// backward compatibility with previous signature
|
// backward compatibility with previous signature
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void enableProtection(EnforcementLevel level, Collection<String> contexts) throws IOException {
|
public void enableProtection(EnforcementLevel level, Collection<String> contexts) throws IOException {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case OFF:
|
case OFF :
|
||||||
disableProtection();
|
disableProtection();
|
||||||
break;
|
break;
|
||||||
case NON_ADMINS:
|
case NON_ADMINS :
|
||||||
case EVERYONE:
|
case EVERYONE :
|
||||||
enableProtection()
|
enableProtection().addRequiredChecks(contexts)
|
||||||
.addRequiredChecks(contexts)
|
.includeAdmins(level == EnforcementLevel.EVERYONE)
|
||||||
.includeAdmins(level==EnforcementLevel.EVERYONE)
|
.enable();
|
||||||
.enable();
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getApiRoute() {
|
String getApiRoute() {
|
||||||
return owner.getApiTailUrl("/branches/"+name);
|
return owner.getApiTailUrl("/branches/" + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -120,7 +173,7 @@ public class GHBranch {
|
|||||||
return "Branch:" + name + " in " + url;
|
return "Branch:" + name + " in " + url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHBranch wrap(GHRepository repo) {
|
GHBranch wrap(GHRepository repo) {
|
||||||
this.owner = repo;
|
this.owner = repo;
|
||||||
this.root = repo.root;
|
this.root = repo.root;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -3,17 +3,22 @@ package org.kohsuke.github;
|
|||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
|
||||||
import static org.kohsuke.github.Previews.ZZZAX;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
|
import static org.kohsuke.github.Previews.ZZZAX;
|
||||||
"URF_UNREAD_FIELD"}, justification = "JSON API")
|
|
||||||
|
/**
|
||||||
|
* The type GHBranchProtection.
|
||||||
|
*/
|
||||||
|
@SuppressFBWarnings(
|
||||||
|
value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
|
||||||
|
"URF_UNREAD_FIELD" },
|
||||||
|
justification = "JSON API")
|
||||||
public class GHBranchProtection {
|
public class GHBranchProtection {
|
||||||
private static final String REQUIRE_SIGNATURES_URI = "/required_signatures";
|
private static final String REQUIRE_SIGNATURES_URI = "/required_signatures";
|
||||||
|
|
||||||
@JsonProperty("enforce_admins")
|
@JsonProperty
|
||||||
private EnforceAdmins enforceAdmins;
|
private EnforceAdmins enforceAdmins;
|
||||||
|
|
||||||
private GitHub root;
|
private GitHub root;
|
||||||
@@ -21,7 +26,7 @@ public class GHBranchProtection {
|
|||||||
@JsonProperty("required_pull_request_reviews")
|
@JsonProperty("required_pull_request_reviews")
|
||||||
private RequiredReviews requiredReviews;
|
private RequiredReviews requiredReviews;
|
||||||
|
|
||||||
@JsonProperty("required_status_checks")
|
@JsonProperty
|
||||||
private RequiredStatusChecks requiredStatusChecks;
|
private RequiredStatusChecks requiredStatusChecks;
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
@@ -30,40 +35,84 @@ public class GHBranchProtection {
|
|||||||
@JsonProperty
|
@JsonProperty
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
@Preview @Deprecated
|
/**
|
||||||
|
* Enabled signed commits.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public void enabledSignedCommits() throws IOException {
|
public void enabledSignedCommits() throws IOException {
|
||||||
requester().method("POST")
|
requester().method("POST").to(url + REQUIRE_SIGNATURES_URI, RequiredSignatures.class);
|
||||||
.to(url + REQUIRE_SIGNATURES_URI, RequiredSignatures.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview @Deprecated
|
/**
|
||||||
|
* Disable signed commits.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public void disableSignedCommits() throws IOException {
|
public void disableSignedCommits() throws IOException {
|
||||||
requester().method("DELETE")
|
requester().method("DELETE").to(url + REQUIRE_SIGNATURES_URI);
|
||||||
.to(url + REQUIRE_SIGNATURES_URI);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets enforce admins.
|
||||||
|
*
|
||||||
|
* @return the enforce admins
|
||||||
|
*/
|
||||||
public EnforceAdmins getEnforceAdmins() {
|
public EnforceAdmins getEnforceAdmins() {
|
||||||
return enforceAdmins;
|
return enforceAdmins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets required reviews.
|
||||||
|
*
|
||||||
|
* @return the required reviews
|
||||||
|
*/
|
||||||
public RequiredReviews getRequiredReviews() {
|
public RequiredReviews getRequiredReviews() {
|
||||||
return requiredReviews;
|
return requiredReviews;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview @Deprecated
|
/**
|
||||||
|
* Gets required signatures.
|
||||||
|
*
|
||||||
|
* @return the required signatures
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public boolean getRequiredSignatures() throws IOException {
|
public boolean getRequiredSignatures() throws IOException {
|
||||||
return requester().method("GET")
|
return requester().method("GET").to(url + REQUIRE_SIGNATURES_URI, RequiredSignatures.class).enabled;
|
||||||
.to(url + REQUIRE_SIGNATURES_URI, RequiredSignatures.class).enabled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets required status checks.
|
||||||
|
*
|
||||||
|
* @return the required status checks
|
||||||
|
*/
|
||||||
public RequiredStatusChecks getRequiredStatusChecks() {
|
public RequiredStatusChecks getRequiredStatusChecks() {
|
||||||
return requiredStatusChecks;
|
return requiredStatusChecks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets restrictions.
|
||||||
|
*
|
||||||
|
* @return the restrictions
|
||||||
|
*/
|
||||||
public Restrictions getRestrictions() {
|
public Restrictions getRestrictions() {
|
||||||
return restrictions;
|
return restrictions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
@@ -77,6 +126,9 @@ public class GHBranchProtection {
|
|||||||
return new Requester(root).withPreview(ZZZAX);
|
return new Requester(root).withPreview(ZZZAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type EnforceAdmins.
|
||||||
|
*/
|
||||||
public static class EnforceAdmins {
|
public static class EnforceAdmins {
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
@@ -84,23 +136,34 @@ public class GHBranchProtection {
|
|||||||
@JsonProperty
|
@JsonProperty
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is enabled boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type RequiredReviews.
|
||||||
|
*/
|
||||||
public static class RequiredReviews {
|
public static class RequiredReviews {
|
||||||
@JsonProperty("dismissal_restrictions")
|
@JsonProperty("dismissal_restrictions")
|
||||||
private Restrictions dismissalRestriction;
|
private Restrictions dismissalRestriction;
|
||||||
|
|
||||||
@JsonProperty("dismiss_stale_reviews")
|
|
||||||
private boolean dismissStaleReviews;
|
private boolean dismissStaleReviews;
|
||||||
|
|
||||||
@JsonProperty("require_code_owner_reviews")
|
|
||||||
private boolean requireCodeOwnerReviews;
|
private boolean requireCodeOwnerReviews;
|
||||||
|
|
||||||
@JsonProperty("required_approving_review_count")
|
@JsonProperty("required_approving_review_count")
|
||||||
@@ -109,22 +172,47 @@ public class GHBranchProtection {
|
|||||||
@JsonProperty
|
@JsonProperty
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets dismissal restrictions.
|
||||||
|
*
|
||||||
|
* @return the dismissal restrictions
|
||||||
|
*/
|
||||||
public Restrictions getDismissalRestrictions() {
|
public Restrictions getDismissalRestrictions() {
|
||||||
return dismissalRestriction;
|
return dismissalRestriction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is dismiss stale reviews boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isDismissStaleReviews() {
|
public boolean isDismissStaleReviews() {
|
||||||
return dismissStaleReviews;
|
return dismissStaleReviews;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is require code owner reviews boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isRequireCodeOwnerReviews() {
|
public boolean isRequireCodeOwnerReviews() {
|
||||||
return requireCodeOwnerReviews;
|
return requireCodeOwnerReviews;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets required reviewers.
|
||||||
|
*
|
||||||
|
* @return the required reviewers
|
||||||
|
*/
|
||||||
public int getRequiredReviewers() {
|
public int getRequiredReviewers() {
|
||||||
return requiredReviewers;
|
return requiredReviewers;
|
||||||
}
|
}
|
||||||
@@ -137,15 +225,28 @@ public class GHBranchProtection {
|
|||||||
@JsonProperty
|
@JsonProperty
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is enabled boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type RequiredStatusChecks.
|
||||||
|
*/
|
||||||
public static class RequiredStatusChecks {
|
public static class RequiredStatusChecks {
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private Collection<String> contexts;
|
private Collection<String> contexts;
|
||||||
@@ -156,24 +257,41 @@ public class GHBranchProtection {
|
|||||||
@JsonProperty
|
@JsonProperty
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets contexts.
|
||||||
|
*
|
||||||
|
* @return the contexts
|
||||||
|
*/
|
||||||
public Collection<String> getContexts() {
|
public Collection<String> getContexts() {
|
||||||
return contexts;
|
return contexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is requires branch up to date boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isRequiresBranchUpToDate() {
|
public boolean isRequiresBranchUpToDate() {
|
||||||
return strict;
|
return strict;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Restrictions.
|
||||||
|
*/
|
||||||
public static class Restrictions {
|
public static class Restrictions {
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private Collection<GHTeam> teams;
|
private Collection<GHTeam> teams;
|
||||||
|
|
||||||
@JsonProperty("teams_url")
|
|
||||||
private String teamsUrl;
|
private String teamsUrl;
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
@@ -182,25 +300,49 @@ public class GHBranchProtection {
|
|||||||
@JsonProperty
|
@JsonProperty
|
||||||
private Collection<GHUser> users;
|
private Collection<GHUser> users;
|
||||||
|
|
||||||
@JsonProperty("users_url")
|
|
||||||
private String usersUrl;
|
private String usersUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets teams.
|
||||||
|
*
|
||||||
|
* @return the teams
|
||||||
|
*/
|
||||||
public Collection<GHTeam> getTeams() {
|
public Collection<GHTeam> getTeams() {
|
||||||
return teams;
|
return teams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets teams url.
|
||||||
|
*
|
||||||
|
* @return the teams url
|
||||||
|
*/
|
||||||
public String getTeamsUrl() {
|
public String getTeamsUrl() {
|
||||||
return teamsUrl;
|
return teamsUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets users.
|
||||||
|
*
|
||||||
|
* @return the users
|
||||||
|
*/
|
||||||
public Collection<GHUser> getUsers() {
|
public Collection<GHUser> getUsers() {
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets users url.
|
||||||
|
*
|
||||||
|
* @return the users url
|
||||||
|
*/
|
||||||
public String getUsersUrl() {
|
public String getUsersUrl() {
|
||||||
return usersUrl;
|
return usersUrl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,12 @@ import static org.kohsuke.github.Previews.*;
|
|||||||
/**
|
/**
|
||||||
* Builder to configure the branch protection settings.
|
* Builder to configure the branch protection settings.
|
||||||
*
|
*
|
||||||
* @see GHBranch#enableProtection()
|
* @see GHBranch#enableProtection() GHBranch#enableProtection()
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
|
@SuppressFBWarnings(
|
||||||
"URF_UNREAD_FIELD" }, justification = "JSON API")
|
value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
|
||||||
|
"URF_UNREAD_FIELD" },
|
||||||
|
justification = "JSON API")
|
||||||
public class GHBranchProtectionBuilder {
|
public class GHBranchProtectionBuilder {
|
||||||
private final GHBranch branch;
|
private final GHBranch branch;
|
||||||
|
|
||||||
@@ -33,25 +35,58 @@ public class GHBranchProtectionBuilder {
|
|||||||
this.branch = branch;
|
this.branch = branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add required checks gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param checks
|
||||||
|
* the checks
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder addRequiredChecks(Collection<String> checks) {
|
public GHBranchProtectionBuilder addRequiredChecks(Collection<String> checks) {
|
||||||
getStatusChecks().contexts.addAll(checks);
|
getStatusChecks().contexts.addAll(checks);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add required checks gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param checks
|
||||||
|
* the checks
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder addRequiredChecks(String... checks) {
|
public GHBranchProtectionBuilder addRequiredChecks(String... checks) {
|
||||||
addRequiredChecks(Arrays.asList(checks));
|
addRequiredChecks(Arrays.asList(checks));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dismiss stale reviews gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder dismissStaleReviews() {
|
public GHBranchProtectionBuilder dismissStaleReviews() {
|
||||||
return dismissStaleReviews(true);
|
return dismissStaleReviews(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dismiss stale reviews gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder dismissStaleReviews(boolean v) {
|
public GHBranchProtectionBuilder dismissStaleReviews(boolean v) {
|
||||||
getPrReviews().put("dismiss_stale_reviews", v);
|
getPrReviews().put("dismiss_stale_reviews", v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable gh branch protection.
|
||||||
|
*
|
||||||
|
* @return the gh branch protection
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHBranchProtection enable() throws IOException {
|
public GHBranchProtection enable() throws IOException {
|
||||||
return requester().method("PUT")
|
return requester().method("PUT")
|
||||||
.withNullable("required_status_checks", statusChecks)
|
.withNullable("required_status_checks", statusChecks)
|
||||||
@@ -62,43 +97,96 @@ public class GHBranchProtectionBuilder {
|
|||||||
.wrap(branch);
|
.wrap(branch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Include admins gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder includeAdmins() {
|
public GHBranchProtectionBuilder includeAdmins() {
|
||||||
return includeAdmins(true);
|
return includeAdmins(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Include admins gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder includeAdmins(boolean v) {
|
public GHBranchProtectionBuilder includeAdmins(boolean v) {
|
||||||
enforceAdmins = v;
|
enforceAdmins = v;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Required reviewers gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder requiredReviewers(int v) {
|
public GHBranchProtectionBuilder requiredReviewers(int v) {
|
||||||
getPrReviews().put("required_approving_review_count", v);
|
getPrReviews().put("required_approving_review_count", v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Require branch is up to date gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder requireBranchIsUpToDate() {
|
public GHBranchProtectionBuilder requireBranchIsUpToDate() {
|
||||||
return requireBranchIsUpToDate(true);
|
return requireBranchIsUpToDate(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Require branch is up to date gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder requireBranchIsUpToDate(boolean v) {
|
public GHBranchProtectionBuilder requireBranchIsUpToDate(boolean v) {
|
||||||
getStatusChecks().strict = v;
|
getStatusChecks().strict = v;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Require code own reviews gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder requireCodeOwnReviews() {
|
public GHBranchProtectionBuilder requireCodeOwnReviews() {
|
||||||
return requireCodeOwnReviews(true);
|
return requireCodeOwnReviews(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Require code own reviews gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder requireCodeOwnReviews(boolean v) {
|
public GHBranchProtectionBuilder requireCodeOwnReviews(boolean v) {
|
||||||
getPrReviews().put("require_code_owner_reviews", v);
|
getPrReviews().put("require_code_owner_reviews", v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Require reviews gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder requireReviews() {
|
public GHBranchProtectionBuilder requireReviews() {
|
||||||
getPrReviews();
|
getPrReviews();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restrict review dismissals gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder restrictReviewDismissals() {
|
public GHBranchProtectionBuilder restrictReviewDismissals() {
|
||||||
getPrReviews();
|
getPrReviews();
|
||||||
|
|
||||||
@@ -109,11 +197,23 @@ public class GHBranchProtectionBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restrict push access gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder restrictPushAccess() {
|
public GHBranchProtectionBuilder restrictPushAccess() {
|
||||||
getRestrictions();
|
getRestrictions();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Team push access gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param teams
|
||||||
|
* the teams
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder teamPushAccess(Collection<GHTeam> teams) {
|
public GHBranchProtectionBuilder teamPushAccess(Collection<GHTeam> teams) {
|
||||||
for (GHTeam team : teams) {
|
for (GHTeam team : teams) {
|
||||||
teamPushAccess(team);
|
teamPushAccess(team);
|
||||||
@@ -121,6 +221,13 @@ public class GHBranchProtectionBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Team push access gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param teams
|
||||||
|
* the teams
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder teamPushAccess(GHTeam... teams) {
|
public GHBranchProtectionBuilder teamPushAccess(GHTeam... teams) {
|
||||||
for (GHTeam team : teams) {
|
for (GHTeam team : teams) {
|
||||||
getRestrictions().teams.add(team.getSlug());
|
getRestrictions().teams.add(team.getSlug());
|
||||||
@@ -128,6 +235,13 @@ public class GHBranchProtectionBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Team review dismissals gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param teams
|
||||||
|
* the teams
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder teamReviewDismissals(Collection<GHTeam> teams) {
|
public GHBranchProtectionBuilder teamReviewDismissals(Collection<GHTeam> teams) {
|
||||||
for (GHTeam team : teams) {
|
for (GHTeam team : teams) {
|
||||||
teamReviewDismissals(team);
|
teamReviewDismissals(team);
|
||||||
@@ -135,6 +249,13 @@ public class GHBranchProtectionBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Team review dismissals gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param teams
|
||||||
|
* the teams
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder teamReviewDismissals(GHTeam... teams) {
|
public GHBranchProtectionBuilder teamReviewDismissals(GHTeam... teams) {
|
||||||
for (GHTeam team : teams) {
|
for (GHTeam team : teams) {
|
||||||
addReviewRestriction(team.getSlug(), true);
|
addReviewRestriction(team.getSlug(), true);
|
||||||
@@ -142,13 +263,27 @@ public class GHBranchProtectionBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User push access gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param users
|
||||||
|
* the users
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder userPushAccess(Collection<GHUser> users) {
|
public GHBranchProtectionBuilder userPushAccess(Collection<GHUser> users) {
|
||||||
for (GHUser user : users) {
|
for (GHUser user : users) {
|
||||||
userPushAccess(user);
|
userPushAccess(user);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User push access gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param users
|
||||||
|
* the users
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder userPushAccess(GHUser... users) {
|
public GHBranchProtectionBuilder userPushAccess(GHUser... users) {
|
||||||
for (GHUser user : users) {
|
for (GHUser user : users) {
|
||||||
getRestrictions().users.add(user.getLogin());
|
getRestrictions().users.add(user.getLogin());
|
||||||
@@ -156,6 +291,13 @@ public class GHBranchProtectionBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User review dismissals gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param users
|
||||||
|
* the users
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder userReviewDismissals(Collection<GHUser> users) {
|
public GHBranchProtectionBuilder userReviewDismissals(Collection<GHUser> users) {
|
||||||
for (GHUser team : users) {
|
for (GHUser team : users) {
|
||||||
userReviewDismissals(team);
|
userReviewDismissals(team);
|
||||||
@@ -163,6 +305,13 @@ public class GHBranchProtectionBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User review dismissals gh branch protection builder.
|
||||||
|
*
|
||||||
|
* @param users
|
||||||
|
* the users
|
||||||
|
* @return the gh branch protection builder
|
||||||
|
*/
|
||||||
public GHBranchProtectionBuilder userReviewDismissals(GHUser... users) {
|
public GHBranchProtectionBuilder userReviewDismissals(GHUser... users) {
|
||||||
for (GHUser user : users) {
|
for (GHUser user : users) {
|
||||||
addReviewRestriction(user.getLogin(), false);
|
addReviewRestriction(user.getLogin(), false);
|
||||||
@@ -173,7 +322,7 @@ public class GHBranchProtectionBuilder {
|
|||||||
private void addReviewRestriction(String restriction, boolean isTeam) {
|
private void addReviewRestriction(String restriction, boolean isTeam) {
|
||||||
restrictReviewDismissals();
|
restrictReviewDismissals();
|
||||||
Restrictions restrictions = (Restrictions) prReviews.get("dismissal_restrictions");
|
Restrictions restrictions = (Restrictions) prReviews.get("dismissal_restrictions");
|
||||||
|
|
||||||
if (isTeam) {
|
if (isTeam) {
|
||||||
restrictions.teams.add(restriction);
|
restrictions.teams.add(restriction);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -15,27 +15,28 @@ import java.util.List;
|
|||||||
* A commit in a repository.
|
* A commit in a repository.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHRepository#getCommit(String)
|
* @see GHRepository#getCommit(String) GHRepository#getCommit(String)
|
||||||
* @see GHCommitComment#getCommit()
|
* @see GHCommitComment#getCommit() GHCommitComment#getCommit()
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = {"NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD"},
|
@SuppressFBWarnings(value = { "NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
|
||||||
justification = "JSON API")
|
|
||||||
public class GHCommit {
|
public class GHCommit {
|
||||||
private GHRepository owner;
|
private GHRepository owner;
|
||||||
|
|
||||||
private ShortInfo commit;
|
private ShortInfo commit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short summary of this commit.
|
* Short summary of this commit.
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
|
@SuppressFBWarnings(
|
||||||
"NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD"}, justification = "JSON API")
|
value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
|
||||||
|
"UWF_UNWRITTEN_FIELD" },
|
||||||
|
justification = "JSON API")
|
||||||
public static class ShortInfo {
|
public static class ShortInfo {
|
||||||
private GHAuthor author;
|
private GHAuthor author;
|
||||||
private GHAuthor committer;
|
private GHAuthor committer;
|
||||||
|
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
private int comment_count;
|
private int comment_count;
|
||||||
|
|
||||||
static class Tree {
|
static class Tree {
|
||||||
@@ -44,88 +45,129 @@ public class GHCommit {
|
|||||||
|
|
||||||
private Tree tree;
|
private Tree tree;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets author.
|
||||||
|
*
|
||||||
|
* @return the author
|
||||||
|
*/
|
||||||
@WithBridgeMethods(value = GHAuthor.class, castRequired = true)
|
@WithBridgeMethods(value = GHAuthor.class, castRequired = true)
|
||||||
public GitUser getAuthor() {
|
public GitUser getAuthor() {
|
||||||
return author;
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets authored date.
|
||||||
|
*
|
||||||
|
* @return the authored date
|
||||||
|
*/
|
||||||
public Date getAuthoredDate() {
|
public Date getAuthoredDate() {
|
||||||
return GitHub.parseDate(author.date);
|
return GitHub.parseDate(author.date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets committer.
|
||||||
|
*
|
||||||
|
* @return the committer
|
||||||
|
*/
|
||||||
@WithBridgeMethods(value = GHAuthor.class, castRequired = true)
|
@WithBridgeMethods(value = GHAuthor.class, castRequired = true)
|
||||||
public GitUser getCommitter() {
|
public GitUser getCommitter() {
|
||||||
return committer;
|
return committer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets commit date.
|
||||||
|
*
|
||||||
|
* @return the commit date
|
||||||
|
*/
|
||||||
public Date getCommitDate() {
|
public Date getCommitDate() {
|
||||||
return GitHub.parseDate(committer.date);
|
return GitHub.parseDate(committer.date);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commit message.
|
* Gets message.
|
||||||
|
*
|
||||||
|
* @return Commit message.
|
||||||
*/
|
*/
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets comment count.
|
||||||
|
*
|
||||||
|
* @return the comment count
|
||||||
|
*/
|
||||||
public int getCommentCount() {
|
public int getCommentCount() {
|
||||||
return comment_count;
|
return comment_count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The type GHAuthor.
|
||||||
|
*
|
||||||
* @deprecated Use {@link GitUser} instead.
|
* @deprecated Use {@link GitUser} instead.
|
||||||
*/
|
*/
|
||||||
public static class GHAuthor extends GitUser {
|
public static class GHAuthor extends GitUser {
|
||||||
private String date;
|
private String date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Stats.
|
||||||
|
*/
|
||||||
public static class Stats {
|
public static class Stats {
|
||||||
int total,additions,deletions;
|
int total, additions, deletions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A file that was modified.
|
* A file that was modified.
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD",
|
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "It's being initilized by JSON deserialization")
|
||||||
justification = "It's being initilized by JSON deserialization")
|
|
||||||
public static class File {
|
public static class File {
|
||||||
String status;
|
String status;
|
||||||
int changes,additions,deletions;
|
int changes, additions, deletions;
|
||||||
String raw_url, blob_url, sha, patch;
|
String raw_url, blob_url, sha, patch;
|
||||||
String filename, previous_filename;
|
String filename, previous_filename;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of lines added + removed.
|
* Gets lines changed.
|
||||||
|
*
|
||||||
|
* @return Number of lines added + removed.
|
||||||
*/
|
*/
|
||||||
public int getLinesChanged() {
|
public int getLinesChanged() {
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of lines added.
|
* Gets lines added.
|
||||||
|
*
|
||||||
|
* @return Number of lines added.
|
||||||
*/
|
*/
|
||||||
public int getLinesAdded() {
|
public int getLinesAdded() {
|
||||||
return additions;
|
return additions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of lines removed.
|
* Gets lines deleted.
|
||||||
|
*
|
||||||
|
* @return Number of lines removed.
|
||||||
*/
|
*/
|
||||||
public int getLinesDeleted() {
|
public int getLinesDeleted() {
|
||||||
return deletions;
|
return deletions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "modified", "added", or "removed"
|
* Gets status.
|
||||||
|
*
|
||||||
|
* @return "modified", "added", or "removed"
|
||||||
*/
|
*/
|
||||||
public String getStatus() {
|
public String getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full path in the repository.
|
* Gets file name.
|
||||||
|
*
|
||||||
|
* @return Full path in the repository.
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = "NM_CONFUSING",
|
@SuppressFBWarnings(value = "NM_CONFUSING",
|
||||||
justification = "It's a part of the library's API and cannot be renamed")
|
justification = "It's a part of the library's API and cannot be renamed")
|
||||||
@@ -134,81 +176,108 @@ public class GHCommit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Previous path, in case file has moved.
|
* Gets previous filename.
|
||||||
|
*
|
||||||
|
* @return Previous path, in case file has moved.
|
||||||
*/
|
*/
|
||||||
public String getPreviousFilename() {
|
public String getPreviousFilename() {
|
||||||
return previous_filename;
|
return previous_filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The actual change.
|
* Gets patch.
|
||||||
|
*
|
||||||
|
* @return The actual change.
|
||||||
*/
|
*/
|
||||||
public String getPatch() {
|
public String getPatch() {
|
||||||
return patch;
|
return patch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL like 'https://raw.github.com/jenkinsci/jenkins/4eb17c197dfdcf8ef7ff87eb160f24f6a20b7f0e/core/pom.xml'
|
* Gets raw url.
|
||||||
* that resolves to the actual content of the file.
|
*
|
||||||
|
* @return URL like
|
||||||
|
* 'https://raw.github.com/jenkinsci/jenkins/4eb17c197dfdcf8ef7ff87eb160f24f6a20b7f0e/core/pom.xml' that
|
||||||
|
* resolves to the actual content of the file.
|
||||||
*/
|
*/
|
||||||
public URL getRawUrl() {
|
public URL getRawUrl() {
|
||||||
return GitHub.parseURL(raw_url);
|
return GitHub.parseURL(raw_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL like 'https://github.com/jenkinsci/jenkins/blob/1182e2ebb1734d0653142bd422ad33c21437f7cf/core/pom.xml'
|
* Gets blob url.
|
||||||
* that resolves to the HTML page that describes this file.
|
*
|
||||||
|
* @return URL like
|
||||||
|
* 'https://github.com/jenkinsci/jenkins/blob/1182e2ebb1734d0653142bd422ad33c21437f7cf/core/pom.xml'
|
||||||
|
* that resolves to the HTML page that describes this file.
|
||||||
*/
|
*/
|
||||||
public URL getBlobUrl() {
|
public URL getBlobUrl() {
|
||||||
return GitHub.parseURL(blob_url);
|
return GitHub.parseURL(blob_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [0-9a-f]{40} SHA1 checksum.
|
* Gets sha.
|
||||||
|
*
|
||||||
|
* @return [0 -9a-f]{40} SHA1 checksum.
|
||||||
*/
|
*/
|
||||||
public String getSha() {
|
public String getSha() {
|
||||||
return sha;
|
return sha;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Parent.
|
||||||
|
*/
|
||||||
public static class Parent {
|
public static class Parent {
|
||||||
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
|
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
|
||||||
String url;
|
String url;
|
||||||
String sha;
|
String sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class User {
|
static class User {
|
||||||
// TODO: what if someone who doesn't have an account on GitHub makes a commit?
|
// TODO: what if someone who doesn't have an account on GitHub makes a commit?
|
||||||
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
|
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
|
||||||
String url,avatar_url,gravatar_id;
|
String url, avatar_url, gravatar_id;
|
||||||
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
|
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
String login;
|
String login;
|
||||||
}
|
}
|
||||||
|
|
||||||
String url,html_url,sha;
|
String url, html_url, sha;
|
||||||
List<File> files;
|
List<File> files;
|
||||||
Stats stats;
|
Stats stats;
|
||||||
List<Parent> parents;
|
List<Parent> parents;
|
||||||
User author,committer;
|
User author, committer;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets commit short info.
|
||||||
|
*
|
||||||
|
* @return the commit short info
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public ShortInfo getCommitShortInfo() throws IOException {
|
public ShortInfo getCommitShortInfo() throws IOException {
|
||||||
if (commit==null)
|
if (commit == null)
|
||||||
populate();
|
populate();
|
||||||
return commit;
|
return commit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The repository that contains the commit.
|
* Gets owner.
|
||||||
|
*
|
||||||
|
* @return the repository that contains the commit.
|
||||||
*/
|
*/
|
||||||
public GHRepository getOwner() {
|
public GHRepository getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of lines added + removed.
|
* Gets lines changed.
|
||||||
|
*
|
||||||
|
* @return the number of lines added + removed.
|
||||||
|
* @throws IOException
|
||||||
|
* if the field was not populated and refresh fails
|
||||||
*/
|
*/
|
||||||
public int getLinesChanged() throws IOException {
|
public int getLinesChanged() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
@@ -216,7 +285,11 @@ public class GHCommit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of lines added.
|
* Gets lines added.
|
||||||
|
*
|
||||||
|
* @return Number of lines added.
|
||||||
|
* @throws IOException
|
||||||
|
* if the field was not populated and refresh fails
|
||||||
*/
|
*/
|
||||||
public int getLinesAdded() throws IOException {
|
public int getLinesAdded() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
@@ -224,7 +297,11 @@ public class GHCommit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of lines removed.
|
* Gets lines deleted.
|
||||||
|
*
|
||||||
|
* @return Number of lines removed.
|
||||||
|
* @throws IOException
|
||||||
|
* if the field was not populated and refresh fails
|
||||||
*/
|
*/
|
||||||
public int getLinesDeleted() throws IOException {
|
public int getLinesDeleted() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
@@ -232,21 +309,30 @@ public class GHCommit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to walk the tree
|
* Use this method to walk the tree.
|
||||||
|
*
|
||||||
|
* @return a GHTree to walk
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
*/
|
*/
|
||||||
public GHTree getTree() throws IOException {
|
public GHTree getTree() throws IOException {
|
||||||
return owner.getTree(getCommitShortInfo().tree.sha);
|
return owner.getTree(getCommitShortInfo().tree.sha);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL of this commit like "https://github.com/kohsuke/sandbox-ant/commit/8ae38db0ea5837313ab5f39d43a6f73de3bd9000"
|
* Gets html url.
|
||||||
|
*
|
||||||
|
* @return URL of this commit like
|
||||||
|
* "https://github.com/kohsuke/sandbox-ant/commit/8ae38db0ea5837313ab5f39d43a6f73de3bd9000"
|
||||||
*/
|
*/
|
||||||
public URL getHtmlUrl() {
|
public URL getHtmlUrl() {
|
||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [0-9a-f]{40} SHA1 checksum.
|
* Gets sha 1.
|
||||||
|
*
|
||||||
|
* @return [0 -9a-f]{40} SHA1 checksum.
|
||||||
*/
|
*/
|
||||||
public String getSHA1() {
|
public String getSHA1() {
|
||||||
return sha;
|
return sha;
|
||||||
@@ -255,19 +341,23 @@ public class GHCommit {
|
|||||||
/**
|
/**
|
||||||
* List of files changed/added/removed in this commit.
|
* List of files changed/added/removed in this commit.
|
||||||
*
|
*
|
||||||
* @return
|
* @return Can be empty but never null.
|
||||||
* Can be empty but never null.
|
* @throws IOException
|
||||||
|
* on error
|
||||||
*/
|
*/
|
||||||
public List<File> getFiles() throws IOException {
|
public List<File> getFiles() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return files!=null ? Collections.unmodifiableList(files) : Collections.<File>emptyList();
|
return files != null ? Collections.unmodifiableList(files) : Collections.<File>emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the SHA1 of parent commit objects.
|
* Gets parent sha 1 s.
|
||||||
|
*
|
||||||
|
* @return SHA1 of parent commit objects.
|
||||||
*/
|
*/
|
||||||
public List<String> getParentSHA1s() {
|
public List<String> getParentSHA1s() {
|
||||||
if (parents==null) return Collections.emptyList();
|
if (parents == null)
|
||||||
|
return Collections.emptyList();
|
||||||
return new AbstractList<String>() {
|
return new AbstractList<String>() {
|
||||||
@Override
|
@Override
|
||||||
public String get(int index) {
|
public String get(int index) {
|
||||||
@@ -283,6 +373,10 @@ public class GHCommit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves the parent commit objects and return them.
|
* Resolves the parent commit objects and return them.
|
||||||
|
*
|
||||||
|
* @return parent commit objects
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
*/
|
*/
|
||||||
public List<GHCommit> getParents() throws IOException {
|
public List<GHCommit> getParents() throws IOException {
|
||||||
List<GHCommit> r = new ArrayList<GHCommit>();
|
List<GHCommit> r = new ArrayList<GHCommit>();
|
||||||
@@ -291,19 +385,35 @@ public class GHCommit {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets author.
|
||||||
|
*
|
||||||
|
* @return the author
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHUser getAuthor() throws IOException {
|
public GHUser getAuthor() throws IOException {
|
||||||
return resolveUser(author);
|
return resolveUser(author);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the date the change was authored on.
|
* Gets the date the change was authored on.
|
||||||
|
*
|
||||||
* @return the date the change was authored on.
|
* @return the date the change was authored on.
|
||||||
* @throws IOException if the information was not already fetched and an attempt at fetching the information failed.
|
* @throws IOException
|
||||||
|
* if the information was not already fetched and an attempt at fetching the information failed.
|
||||||
*/
|
*/
|
||||||
public Date getAuthoredDate() throws IOException {
|
public Date getAuthoredDate() throws IOException {
|
||||||
return getCommitShortInfo().getAuthoredDate();
|
return getCommitShortInfo().getAuthoredDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets committer.
|
||||||
|
*
|
||||||
|
* @return the committer
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHUser getCommitter() throws IOException {
|
public GHUser getCommitter() throws IOException {
|
||||||
return resolveUser(committer);
|
return resolveUser(committer);
|
||||||
}
|
}
|
||||||
@@ -312,62 +422,89 @@ public class GHCommit {
|
|||||||
* Gets the date the change was committed on.
|
* Gets the date the change was committed on.
|
||||||
*
|
*
|
||||||
* @return the date the change was committed on.
|
* @return the date the change was committed on.
|
||||||
* @throws IOException if the information was not already fetched and an attempt at fetching the information failed.
|
* @throws IOException
|
||||||
|
* if the information was not already fetched and an attempt at fetching the information failed.
|
||||||
*/
|
*/
|
||||||
public Date getCommitDate() throws IOException {
|
public Date getCommitDate() throws IOException {
|
||||||
return getCommitShortInfo().getCommitDate();
|
return getCommitShortInfo().getCommitDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private GHUser resolveUser(User author) throws IOException {
|
private GHUser resolveUser(User author) throws IOException {
|
||||||
if (author==null || author.login==null) return null;
|
if (author == null || author.login == null)
|
||||||
|
return null;
|
||||||
return owner.root.getUser(author.login);
|
return owner.root.getUser(author.login);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists up all the commit comments in this repository.
|
* List comments paged iterable.
|
||||||
|
*
|
||||||
|
* @return {@link PagedIterable} with all the commit comments in this repository.
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHCommitComment> listComments() {
|
public PagedIterable<GHCommitComment> listComments() {
|
||||||
return new PagedIterable<GHCommitComment>() {
|
return owner.root.retrieve()
|
||||||
public PagedIterator<GHCommitComment> _iterator(int pageSize) {
|
.asPagedIterable(
|
||||||
return new PagedIterator<GHCommitComment>(owner.root.retrieve().asIterator(String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha), GHCommitComment[].class, pageSize)) {
|
String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha),
|
||||||
@Override
|
GHCommitComment[].class,
|
||||||
protected void wrapUp(GHCommitComment[] page) {
|
item -> item.wrap(owner));
|
||||||
for (GHCommitComment c : page)
|
|
||||||
c.wrap(owner);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a commit comment.
|
* Creates a commit comment.
|
||||||
*
|
* <p>
|
||||||
* I'm not sure how path/line/position parameters interact with each other.
|
* I'm not sure how path/line/position parameters interact with each other.
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* body of the comment
|
||||||
|
* @param path
|
||||||
|
* path of file being commented on
|
||||||
|
* @param line
|
||||||
|
* target line for comment
|
||||||
|
* @param position
|
||||||
|
* position on line
|
||||||
|
* @return created GHCommitComment
|
||||||
|
* @throws IOException
|
||||||
|
* if comment is not created
|
||||||
*/
|
*/
|
||||||
public GHCommitComment createComment(String body, String path, Integer line, Integer position) throws IOException {
|
public GHCommitComment createComment(String body, String path, Integer line, Integer position) throws IOException {
|
||||||
GHCommitComment r = new Requester(owner.root)
|
GHCommitComment r = new Requester(owner.root).with("body", body)
|
||||||
.with("body",body)
|
.with("path", path)
|
||||||
.with("path",path)
|
.with("line", line)
|
||||||
.with("line",line)
|
.with("position", position)
|
||||||
.with("position",position)
|
.to(String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha),
|
||||||
.to(String.format("/repos/%s/%s/commits/%s/comments",owner.getOwnerName(),owner.getName(),sha),GHCommitComment.class);
|
GHCommitComment.class);
|
||||||
return r.wrap(owner);
|
return r.wrap(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create comment gh commit comment.
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @return the gh commit comment
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHCommitComment createComment(String body) throws IOException {
|
public GHCommitComment createComment(String body) throws IOException {
|
||||||
return createComment(body, null, null, null);
|
return createComment(body, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the status of this commit, newer ones first.
|
* List statuses paged iterable.
|
||||||
|
*
|
||||||
|
* @return status of this commit, newer ones first.
|
||||||
|
* @throws IOException
|
||||||
|
* if statuses cannot be read
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHCommitStatus> listStatuses() throws IOException {
|
public PagedIterable<GHCommitStatus> listStatuses() throws IOException {
|
||||||
return owner.listCommitStatuses(sha);
|
return owner.listCommitStatuses(sha);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the last status of this commit, which is what gets shown in the UI.
|
* Gets last status.
|
||||||
|
*
|
||||||
|
* @return the last status of this commit, which is what gets shown in the UI.
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
*/
|
*/
|
||||||
public GHCommitStatus getLastStatus() throws IOException {
|
public GHCommitStatus getLastStatus() throws IOException {
|
||||||
return owner.getLastCommitStatus(sha);
|
return owner.getLastCommitStatus(sha);
|
||||||
@@ -375,9 +512,12 @@ public class GHCommit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Some of the fields are not always filled in when this object is retrieved as a part of another API call.
|
* Some of the fields are not always filled in when this object is retrieved as a part of another API call.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
*/
|
*/
|
||||||
void populate() throws IOException {
|
void populate() throws IOException {
|
||||||
if (files==null && stats==null)
|
if (files == null && stats == null)
|
||||||
owner.root.retrieve().to(owner.getApiTailUrl("commits/" + sha), this);
|
owner.root.retrieve().to(owner.getApiTailUrl("commits/" + sha), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import java.util.List;
|
|||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder pattern for creating a new commit.
|
* Builder pattern for creating a new commit. Based on https://developer.github.com/v3/git/commits/#create-a-commit
|
||||||
* Based on https://developer.github.com/v3/git/commits/#create-a-commit
|
|
||||||
*/
|
*/
|
||||||
public class GHCommitBuilder {
|
public class GHCommitBuilder {
|
||||||
private final GHRepository repo;
|
private final GHRepository repo;
|
||||||
@@ -39,7 +38,11 @@ public class GHCommitBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param message the commit message
|
* Message gh commit builder.
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
* the commit message
|
||||||
|
* @return the gh commit builder
|
||||||
*/
|
*/
|
||||||
public GHCommitBuilder message(String message) {
|
public GHCommitBuilder message(String message) {
|
||||||
req.with("message", message);
|
req.with("message", message);
|
||||||
@@ -47,7 +50,11 @@ public class GHCommitBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tree the SHA of the tree object this commit points to
|
* Tree gh commit builder.
|
||||||
|
*
|
||||||
|
* @param tree
|
||||||
|
* the SHA of the tree object this commit points to
|
||||||
|
* @return the gh commit builder
|
||||||
*/
|
*/
|
||||||
public GHCommitBuilder tree(String tree) {
|
public GHCommitBuilder tree(String tree) {
|
||||||
req.with("tree", tree);
|
req.with("tree", tree);
|
||||||
@@ -55,7 +62,11 @@ public class GHCommitBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param parent the SHA of a parent commit.
|
* Parent gh commit builder.
|
||||||
|
*
|
||||||
|
* @param parent
|
||||||
|
* the SHA of a parent commit.
|
||||||
|
* @return the gh commit builder
|
||||||
*/
|
*/
|
||||||
public GHCommitBuilder parent(String parent) {
|
public GHCommitBuilder parent(String parent) {
|
||||||
parents.add(parent);
|
parents.add(parent);
|
||||||
@@ -64,17 +75,33 @@ public class GHCommitBuilder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the author of this commit.
|
* Configures the author of this commit.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @param email
|
||||||
|
* the email
|
||||||
|
* @param date
|
||||||
|
* the date
|
||||||
|
* @return the gh commit builder
|
||||||
*/
|
*/
|
||||||
public GHCommitBuilder author(String name, String email, Date date) {
|
public GHCommitBuilder author(String name, String email, Date date) {
|
||||||
req._with("author", new UserInfo(name, email, date));
|
req.with("author", new UserInfo(name, email, date));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the committer of this commit.
|
* Configures the committer of this commit.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @param email
|
||||||
|
* the email
|
||||||
|
* @param date
|
||||||
|
* the date
|
||||||
|
* @return the gh commit builder
|
||||||
*/
|
*/
|
||||||
public GHCommitBuilder committer(String name, String email, Date date) {
|
public GHCommitBuilder committer(String name, String email, Date date) {
|
||||||
req._with("committer", new UserInfo(name, email, date));
|
req.with("committer", new UserInfo(name, email, date));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,9 +111,13 @@ public class GHCommitBuilder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a blob based on the parameters specified thus far.
|
* Creates a blob based on the parameters specified thus far.
|
||||||
|
*
|
||||||
|
* @return the gh commit
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHCommit create() throws IOException {
|
public GHCommit create() throws IOException {
|
||||||
req._with("parents", parents);
|
req.with("parents", parents);
|
||||||
return req.method("POST").to(getApiTail(), GHCommit.class).wrapUp(repo);
|
return req.method("POST").to(getApiTail(), GHCommit.class).wrapUp(repo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,61 +11,83 @@ import static org.kohsuke.github.Previews.*;
|
|||||||
* A comment attached to a commit (or a specific line in a specific file of a commit.)
|
* A comment attached to a commit (or a specific line in a specific file of a commit.)
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHRepository#listCommitComments()
|
* @see GHRepository#listCommitComments() GHRepository#listCommitComments()
|
||||||
* @see GHCommit#listComments()
|
* @see GHCommit#listComments() GHCommit#listComments()
|
||||||
* @see GHCommit#createComment(String, String, Integer, Integer)
|
* @see GHCommit#createComment(String, String, Integer, Integer) GHCommit#createComment(String, String, Integer,
|
||||||
|
* Integer)
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
|
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
|
||||||
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
|
justification = "JSON API")
|
||||||
public class GHCommitComment extends GHObject implements Reactable {
|
public class GHCommitComment extends GHObject implements Reactable {
|
||||||
private GHRepository owner;
|
private GHRepository owner;
|
||||||
|
|
||||||
String body, html_url, commit_id;
|
String body, html_url, commit_id;
|
||||||
Integer line;
|
Integer line;
|
||||||
String path;
|
String path;
|
||||||
GHUser user; // not fully populated. beware.
|
GHUser user; // not fully populated. beware.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets owner.
|
||||||
|
*
|
||||||
|
* @return the owner
|
||||||
|
*/
|
||||||
public GHRepository getOwner() {
|
public GHRepository getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL like 'https://github.com/kohsuke/sandbox-ant/commit/8ae38db0ea5837313ab5f39d43a6f73de3bd9000#commitcomment-1252827' to
|
* URL like
|
||||||
|
* 'https://github.com/kohsuke/sandbox-ant/commit/8ae38db0ea5837313ab5f39d43a6f73de3bd9000#commitcomment-1252827' to
|
||||||
* show this commit comment in a browser.
|
* show this commit comment in a browser.
|
||||||
*/
|
*/
|
||||||
public URL getHtmlUrl() {
|
public URL getHtmlUrl() {
|
||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets sha 1.
|
||||||
|
*
|
||||||
|
* @return the sha 1
|
||||||
|
*/
|
||||||
public String getSHA1() {
|
public String getSHA1() {
|
||||||
return commit_id;
|
return commit_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commit comment in the GitHub flavored markdown format.
|
* Commit comment in the GitHub flavored markdown format.
|
||||||
|
*
|
||||||
|
* @return the body
|
||||||
*/
|
*/
|
||||||
public String getBody() {
|
public String getBody() {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A commit comment can be on a specific line of a specific file, if so, this field points to a file.
|
* A commit comment can be on a specific line of a specific file, if so, this field points to a file. Otherwise
|
||||||
* Otherwise null.
|
* null.
|
||||||
|
*
|
||||||
|
* @return the path
|
||||||
*/
|
*/
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A commit comment can be on a specific line of a specific file, if so, this field points to the line number in the file.
|
* A commit comment can be on a specific line of a specific file, if so, this field points to the line number in the
|
||||||
* Otherwise -1.
|
* file. Otherwise -1.
|
||||||
|
*
|
||||||
|
* @return the line
|
||||||
*/
|
*/
|
||||||
public int getLine() {
|
public int getLine() {
|
||||||
return line!=null ? line : -1;
|
return line != null ? line : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the user who put this comment.
|
* Gets the user who put this comment.
|
||||||
|
*
|
||||||
|
* @return the user
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHUser getUser() throws IOException {
|
public GHUser getUser() throws IOException {
|
||||||
return owner == null || owner.root.isOffline() ? user : owner.root.getUser(user.login);
|
return owner == null || owner.root.isOffline() ? user : owner.root.getUser(user.login);
|
||||||
@@ -73,6 +95,10 @@ public class GHCommitComment extends GHObject implements Reactable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the commit to which this comment is associated with.
|
* Gets the commit to which this comment is associated with.
|
||||||
|
*
|
||||||
|
* @return the commit
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHCommit getCommit() throws IOException {
|
public GHCommit getCommit() throws IOException {
|
||||||
return getOwner().getCommit(getSHA1());
|
return getOwner().getCommit(getSHA1());
|
||||||
@@ -80,49 +106,48 @@ public class GHCommitComment extends GHObject implements Reactable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the body of the commit message.
|
* Updates the body of the commit message.
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void update(String body) throws IOException {
|
public void update(String body) throws IOException {
|
||||||
new Requester(owner.root)
|
new Requester(owner.root).with("body", body).method("PATCH").to(getApiTail(), GHCommitComment.class);
|
||||||
.with("body", body)
|
|
||||||
.method("PATCH").to(getApiTail(), GHCommitComment.class);
|
|
||||||
this.body = body;
|
this.body = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview @Deprecated
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public GHReaction createReaction(ReactionContent content) throws IOException {
|
public GHReaction createReaction(ReactionContent content) throws IOException {
|
||||||
return new Requester(owner.root)
|
return new Requester(owner.root).withPreview(SQUIRREL_GIRL)
|
||||||
.withPreview(SQUIRREL_GIRL)
|
|
||||||
.with("content", content.getContent())
|
.with("content", content.getContent())
|
||||||
.to(getApiTail()+"/reactions", GHReaction.class).wrap(owner.root);
|
.to(getApiTail() + "/reactions", GHReaction.class)
|
||||||
|
.wrap(owner.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview @Deprecated
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public PagedIterable<GHReaction> listReactions() {
|
public PagedIterable<GHReaction> listReactions() {
|
||||||
return new PagedIterable<GHReaction>() {
|
return owner.root.retrieve()
|
||||||
public PagedIterator<GHReaction> _iterator(int pageSize) {
|
.withPreview(SQUIRREL_GIRL)
|
||||||
return new PagedIterator<GHReaction>(owner.root.retrieve().withPreview(SQUIRREL_GIRL).asIterator(getApiTail()+"/reactions", GHReaction[].class, pageSize)) {
|
.asPagedIterable(getApiTail() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root));
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHReaction[] page) {
|
|
||||||
for (GHReaction c : page)
|
|
||||||
c.wrap(owner.root);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes this comment.
|
* Deletes this comment.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(owner.root).method("DELETE").to(getApiTail());
|
new Requester(owner.root).method("DELETE").to(getApiTail());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getApiTail() {
|
private String getApiTail() {
|
||||||
return String.format("/repos/%s/%s/comments/%s",owner.getOwnerName(),owner.getName(),id);
|
return String.format("/repos/%s/%s/comments/%s", owner.getOwnerName(), owner.getName(), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GHCommitComment wrap(GHRepository owner) {
|
GHCommitComment wrap(GHRepository owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
if (owner.root.isOffline()) {
|
if (owner.root.isOffline()) {
|
||||||
|
|||||||
@@ -36,16 +36,22 @@ public class GHCommitPointer {
|
|||||||
private GHRepository repo;
|
private GHRepository repo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This points to the user who owns
|
* This points to the user who owns the {@link #getRepository()}.
|
||||||
* the {@link #getRepository()}.
|
*
|
||||||
|
* @return the user
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHUser getUser() throws IOException {
|
public GHUser getUser() throws IOException {
|
||||||
if (user != null) return user.root.intern(user);
|
if (user != null)
|
||||||
|
return user.root.intern(user);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The repository that contains the commit.
|
* The repository that contains the commit.
|
||||||
|
*
|
||||||
|
* @return the repository
|
||||||
*/
|
*/
|
||||||
public GHRepository getRepository() {
|
public GHRepository getRepository() {
|
||||||
return repo;
|
return repo;
|
||||||
@@ -53,6 +59,8 @@ public class GHCommitPointer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Named ref to the commit. This appears to be a "short ref" that doesn't include "refs/heads/" portion.
|
* Named ref to the commit. This appears to be a "short ref" that doesn't include "refs/heads/" portion.
|
||||||
|
*
|
||||||
|
* @return the ref
|
||||||
*/
|
*/
|
||||||
public String getRef() {
|
public String getRef() {
|
||||||
return ref;
|
return ref;
|
||||||
@@ -60,6 +68,8 @@ public class GHCommitPointer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* SHA1 of the commit.
|
* SHA1 of the commit.
|
||||||
|
*
|
||||||
|
* @return the sha
|
||||||
*/
|
*/
|
||||||
public String getSha() {
|
public String getSha() {
|
||||||
return sha;
|
return sha;
|
||||||
@@ -67,6 +77,8 @@ public class GHCommitPointer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* String that looks like "USERNAME:REF".
|
* String that looks like "USERNAME:REF".
|
||||||
|
*
|
||||||
|
* @return the label
|
||||||
*/
|
*/
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
@@ -74,13 +86,19 @@ public class GHCommitPointer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains the commit that this pointer is referring to.
|
* Obtains the commit that this pointer is referring to.
|
||||||
|
*
|
||||||
|
* @return the commit
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHCommit getCommit() throws IOException {
|
public GHCommit getCommit() throws IOException {
|
||||||
return getRepository().getCommit(getSha());
|
return getRepository().getCommit(getSha());
|
||||||
}
|
}
|
||||||
|
|
||||||
void wrapUp(GitHub root) {
|
void wrapUp(GitHub root) {
|
||||||
if (user!=null) user.root = root;
|
if (user != null)
|
||||||
if (repo!=null) repo.wrap(root);
|
user.root = root;
|
||||||
|
if (repo != null)
|
||||||
|
repo.wrap(root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,57 +16,83 @@ import java.util.Date;
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHRepository#queryCommits()
|
* @see GHRepository#queryCommits() GHRepository#queryCommits()
|
||||||
*/
|
*/
|
||||||
public class GHCommitQueryBuilder {
|
public class GHCommitQueryBuilder {
|
||||||
private final Requester req;
|
private final Requester req;
|
||||||
private final GHRepository repo;
|
private final GHRepository repo;
|
||||||
|
|
||||||
/*package*/ GHCommitQueryBuilder(GHRepository repo) {
|
GHCommitQueryBuilder(GHRepository repo) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.req = repo.root.retrieve(); // requester to build up
|
this.req = repo.root.retrieve(); // requester to build up
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GItHub login or email address by which to filter by commit author.
|
* GItHub login or email address by which to filter by commit author.
|
||||||
|
*
|
||||||
|
* @param author
|
||||||
|
* the author
|
||||||
|
* @return the gh commit query builder
|
||||||
*/
|
*/
|
||||||
public GHCommitQueryBuilder author(String author) {
|
public GHCommitQueryBuilder author(String author) {
|
||||||
req.with("author",author);
|
req.with("author", author);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only commits containing this file path will be returned.
|
* Only commits containing this file path will be returned.
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
|
* the path
|
||||||
|
* @return the gh commit query builder
|
||||||
*/
|
*/
|
||||||
public GHCommitQueryBuilder path(String path) {
|
public GHCommitQueryBuilder path(String path) {
|
||||||
req.with("path",path);
|
req.with("path", path);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the SHA1 commit / tag / branch / etc to start listing commits from.
|
* Specifies the SHA1 commit / tag / branch / etc to start listing commits from.
|
||||||
*
|
*
|
||||||
|
* @param ref
|
||||||
|
* the ref
|
||||||
|
* @return the gh commit query builder
|
||||||
*/
|
*/
|
||||||
public GHCommitQueryBuilder from(String ref) {
|
public GHCommitQueryBuilder from(String ref) {
|
||||||
req.with("sha",ref);
|
req.with("sha", ref);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page size gh commit query builder.
|
||||||
|
*
|
||||||
|
* @param pageSize
|
||||||
|
* the page size
|
||||||
|
* @return the gh commit query builder
|
||||||
|
*/
|
||||||
public GHCommitQueryBuilder pageSize(int pageSize) {
|
public GHCommitQueryBuilder pageSize(int pageSize) {
|
||||||
req.with("per_page",pageSize);
|
req.with("per_page", pageSize);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only commits after this date will be returned
|
* Only commits after this date will be returned
|
||||||
|
*
|
||||||
|
* @param dt
|
||||||
|
* the dt
|
||||||
|
* @return the gh commit query builder
|
||||||
*/
|
*/
|
||||||
public GHCommitQueryBuilder since(Date dt) {
|
public GHCommitQueryBuilder since(Date dt) {
|
||||||
req.with("since",GitHub.printDate(dt));
|
req.with("since", GitHub.printDate(dt));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only commits after this date will be returned
|
* Only commits after this date will be returned
|
||||||
|
*
|
||||||
|
* @param timestamp
|
||||||
|
* the timestamp
|
||||||
|
* @return the gh commit query builder
|
||||||
*/
|
*/
|
||||||
public GHCommitQueryBuilder since(long timestamp) {
|
public GHCommitQueryBuilder since(long timestamp) {
|
||||||
return since(new Date(timestamp));
|
return since(new Date(timestamp));
|
||||||
@@ -74,14 +100,22 @@ public class GHCommitQueryBuilder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Only commits before this date will be returned
|
* Only commits before this date will be returned
|
||||||
|
*
|
||||||
|
* @param dt
|
||||||
|
* the dt
|
||||||
|
* @return the gh commit query builder
|
||||||
*/
|
*/
|
||||||
public GHCommitQueryBuilder until(Date dt) {
|
public GHCommitQueryBuilder until(Date dt) {
|
||||||
req.with("until",GitHub.printDate(dt));
|
req.with("until", GitHub.printDate(dt));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only commits before this date will be returned
|
* Only commits before this date will be returned
|
||||||
|
*
|
||||||
|
* @param timestamp
|
||||||
|
* the timestamp
|
||||||
|
* @return the gh commit query builder
|
||||||
*/
|
*/
|
||||||
public GHCommitQueryBuilder until(long timestamp) {
|
public GHCommitQueryBuilder until(long timestamp) {
|
||||||
return until(new Date(timestamp));
|
return until(new Date(timestamp));
|
||||||
@@ -89,17 +123,10 @@ public class GHCommitQueryBuilder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists up the commits with the criteria built so far.
|
* Lists up the commits with the criteria built so far.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHCommit> list() {
|
public PagedIterable<GHCommit> list() {
|
||||||
return new PagedIterable<GHCommit>() {
|
return req.asPagedIterable(repo.getApiTailUrl("commits"), GHCommit[].class, item -> item.wrapUp(repo));
|
||||||
public PagedIterator<GHCommit> _iterator(int pageSize) {
|
|
||||||
return new PagedIterator<GHCommit>(req.asIterator(repo.getApiTailUrl("commits"), GHCommit[].class, pageSize)) {
|
|
||||||
protected void wrapUp(GHCommit[] page) {
|
|
||||||
for (GHCommit c : page)
|
|
||||||
c.wrapUp(repo);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ import java.io.IOException;
|
|||||||
* Search commits.
|
* Search commits.
|
||||||
*
|
*
|
||||||
* @author Marc de Verdelhan
|
* @author Marc de Verdelhan
|
||||||
* @see GitHub#searchCommits()
|
* @see GitHub#searchCommits() GitHub#searchCommits()
|
||||||
*/
|
*/
|
||||||
@Preview @Deprecated
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public class GHCommitSearchBuilder extends GHSearchBuilder<GHCommit> {
|
public class GHCommitSearchBuilder extends GHSearchBuilder<GHCommit> {
|
||||||
/*package*/ GHCommitSearchBuilder(GitHub root) {
|
GHCommitSearchBuilder(GitHub root) {
|
||||||
super(root,CommitSearchResult.class);
|
super(root, CommitSearchResult.class);
|
||||||
req.withPreview(Previews.CLOAK);
|
req.withPreview(Previews.CLOAK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,100 +26,233 @@ public class GHCommitSearchBuilder extends GHSearchBuilder<GHCommit> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder author(String v) {
|
public GHCommitSearchBuilder author(String v) {
|
||||||
return q("author:"+v);
|
return q("author:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Committer gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder committer(String v) {
|
public GHCommitSearchBuilder committer(String v) {
|
||||||
return q("committer:"+v);
|
return q("committer:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author name gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder authorName(String v) {
|
public GHCommitSearchBuilder authorName(String v) {
|
||||||
return q("author-name:"+v);
|
return q("author-name:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Committer name gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder committerName(String v) {
|
public GHCommitSearchBuilder committerName(String v) {
|
||||||
return q("committer-name:"+v);
|
return q("committer-name:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author email gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder authorEmail(String v) {
|
public GHCommitSearchBuilder authorEmail(String v) {
|
||||||
return q("author-email:"+v);
|
return q("author-email:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Committer email gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder committerEmail(String v) {
|
public GHCommitSearchBuilder committerEmail(String v) {
|
||||||
return q("committer-email:"+v);
|
return q("committer-email:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author date gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder authorDate(String v) {
|
public GHCommitSearchBuilder authorDate(String v) {
|
||||||
return q("author-date:"+v);
|
return q("author-date:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Committer date gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder committerDate(String v) {
|
public GHCommitSearchBuilder committerDate(String v) {
|
||||||
return q("committer-date:"+v);
|
return q("committer-date:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param merge
|
||||||
|
* the merge
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder merge(boolean merge) {
|
public GHCommitSearchBuilder merge(boolean merge) {
|
||||||
return q("merge:"+Boolean.valueOf(merge).toString().toLowerCase());
|
return q("merge:" + Boolean.valueOf(merge).toString().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hash gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder hash(String v) {
|
public GHCommitSearchBuilder hash(String v) {
|
||||||
return q("hash:"+v);
|
return q("hash:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parent gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder parent(String v) {
|
public GHCommitSearchBuilder parent(String v) {
|
||||||
return q("parent:"+v);
|
return q("parent:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tree gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder tree(String v) {
|
public GHCommitSearchBuilder tree(String v) {
|
||||||
return q("tree:"+v);
|
return q("tree:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder is(String v) {
|
public GHCommitSearchBuilder is(String v) {
|
||||||
return q("is:"+v);
|
return q("is:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder user(String v) {
|
public GHCommitSearchBuilder user(String v) {
|
||||||
return q("user:"+v);
|
return q("user:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Org gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder org(String v) {
|
public GHCommitSearchBuilder org(String v) {
|
||||||
return q("org:"+v);
|
return q("org:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repo gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder repo(String v) {
|
public GHCommitSearchBuilder repo(String v) {
|
||||||
return q("repo:"+v);
|
return q("repo:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Order gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder order(GHDirection v) {
|
public GHCommitSearchBuilder order(GHDirection v) {
|
||||||
req.with("order",v);
|
req.with("order", v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort gh commit search builder.
|
||||||
|
*
|
||||||
|
* @param sort
|
||||||
|
* the sort
|
||||||
|
* @return the gh commit search builder
|
||||||
|
*/
|
||||||
public GHCommitSearchBuilder sort(Sort sort) {
|
public GHCommitSearchBuilder sort(Sort sort) {
|
||||||
req.with("sort",sort);
|
req.with("sort", sort);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Sort { AUTHOR_DATE, COMMITTER_DATE }
|
/**
|
||||||
|
* The enum Sort.
|
||||||
|
*/
|
||||||
|
public enum Sort {
|
||||||
|
AUTHOR_DATE, COMMITTER_DATE
|
||||||
|
}
|
||||||
|
|
||||||
private static class CommitSearchResult extends SearchResult<GHCommit> {
|
private static class CommitSearchResult extends SearchResult<GHCommit> {
|
||||||
private GHCommit[] items;
|
private GHCommit[] items;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/*package*/ GHCommit[] getItems(GitHub root) {
|
GHCommit[] getItems(GitHub root) {
|
||||||
for (GHCommit commit : items) {
|
for (GHCommit commit : items) {
|
||||||
String repoName = getRepoName(commit.url);
|
String repoName = getRepoName(commit.url);
|
||||||
try {
|
try {
|
||||||
GHRepository repo = root.getRepository(repoName);
|
GHRepository repo = root.getRepository(repoName);
|
||||||
commit.wrapUp(repo);
|
commit.wrapUp(repo);
|
||||||
} catch (IOException ioe) {}
|
} catch (IOException ioe) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param commitUrl a commit URL
|
* @param commitUrl
|
||||||
|
* a commit URL
|
||||||
* @return the repo name ("username/reponame")
|
* @return the repo name ("username/reponame")
|
||||||
*/
|
*/
|
||||||
private static String getRepoName(String commitUrl) {
|
private static String getRepoName(String commitUrl) {
|
||||||
|
|||||||
@@ -7,49 +7,75 @@ import java.net.URL;
|
|||||||
* Represents a status of a commit.
|
* Represents a status of a commit.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHRepository#getLastCommitStatus(String)
|
* @see GHRepository#getLastCommitStatus(String) GHRepository#getLastCommitStatus(String)
|
||||||
* @see GHCommit#getLastStatus()
|
* @see GHCommit#getLastStatus() GHCommit#getLastStatus()
|
||||||
* @see GHRepository#createCommitStatus(String, GHCommitState, String, String)
|
* @see GHRepository#createCommitStatus(String, GHCommitState, String, String) GHRepository#createCommitStatus(String,
|
||||||
|
* GHCommitState, String, String)
|
||||||
*/
|
*/
|
||||||
public class GHCommitStatus extends GHObject {
|
public class GHCommitStatus extends GHObject {
|
||||||
String state;
|
String state;
|
||||||
String target_url,description;
|
String target_url, description;
|
||||||
String context;
|
String context;
|
||||||
GHUser creator;
|
GHUser creator;
|
||||||
|
|
||||||
private GitHub root;
|
private GitHub root;
|
||||||
|
|
||||||
/*package*/ GHCommitStatus wrapUp(GitHub root) {
|
GHCommitStatus wrapUp(GitHub root) {
|
||||||
if (creator!=null) creator.wrapUp(root);
|
if (creator != null)
|
||||||
|
creator.wrapUp(root);
|
||||||
this.root = root;
|
this.root = root;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets state.
|
||||||
|
*
|
||||||
|
* @return the state
|
||||||
|
*/
|
||||||
public GHCommitState getState() {
|
public GHCommitState getState() {
|
||||||
for (GHCommitState s : GHCommitState.values()) {
|
for (GHCommitState s : GHCommitState.values()) {
|
||||||
if (s.name().equalsIgnoreCase(state))
|
if (s.name().equalsIgnoreCase(state))
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Unexpected state: "+state);
|
throw new IllegalStateException("Unexpected state: " + state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The URL that this status is linked to.
|
* The URL that this status is linked to.
|
||||||
*
|
* <p>
|
||||||
* This is the URL specified when creating a commit status.
|
* This is the URL specified when creating a commit status.
|
||||||
|
*
|
||||||
|
* @return the target url
|
||||||
*/
|
*/
|
||||||
public String getTargetUrl() {
|
public String getTargetUrl() {
|
||||||
return target_url;
|
return target_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets description.
|
||||||
|
*
|
||||||
|
* @return the description
|
||||||
|
*/
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets creator.
|
||||||
|
*
|
||||||
|
* @return the creator
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHUser getCreator() throws IOException {
|
public GHUser getCreator() throws IOException {
|
||||||
return root.intern(creator);
|
return root.intern(creator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets context.
|
||||||
|
*
|
||||||
|
* @return the context
|
||||||
|
*/
|
||||||
public String getContext() {
|
public String getContext() {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,52 +21,108 @@ public class GHCompare {
|
|||||||
|
|
||||||
private GHRepository owner;
|
private GHRepository owner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public URL getUrl() {
|
public URL getUrl() {
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets html url.
|
||||||
|
*
|
||||||
|
* @return the html url
|
||||||
|
*/
|
||||||
public URL getHtmlUrl() {
|
public URL getHtmlUrl() {
|
||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets permalink url.
|
||||||
|
*
|
||||||
|
* @return the permalink url
|
||||||
|
*/
|
||||||
public URL getPermalinkUrl() {
|
public URL getPermalinkUrl() {
|
||||||
return GitHub.parseURL(permalink_url);
|
return GitHub.parseURL(permalink_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets diff url.
|
||||||
|
*
|
||||||
|
* @return the diff url
|
||||||
|
*/
|
||||||
public URL getDiffUrl() {
|
public URL getDiffUrl() {
|
||||||
return GitHub.parseURL(diff_url);
|
return GitHub.parseURL(diff_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets patch url.
|
||||||
|
*
|
||||||
|
* @return the patch url
|
||||||
|
*/
|
||||||
public URL getPatchUrl() {
|
public URL getPatchUrl() {
|
||||||
return GitHub.parseURL(patch_url);
|
return GitHub.parseURL(patch_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets status.
|
||||||
|
*
|
||||||
|
* @return the status
|
||||||
|
*/
|
||||||
public Status getStatus() {
|
public Status getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets ahead by.
|
||||||
|
*
|
||||||
|
* @return the ahead by
|
||||||
|
*/
|
||||||
public int getAheadBy() {
|
public int getAheadBy() {
|
||||||
return ahead_by;
|
return ahead_by;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets behind by.
|
||||||
|
*
|
||||||
|
* @return the behind by
|
||||||
|
*/
|
||||||
public int getBehindBy() {
|
public int getBehindBy() {
|
||||||
return behind_by;
|
return behind_by;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets total commits.
|
||||||
|
*
|
||||||
|
* @return the total commits
|
||||||
|
*/
|
||||||
public int getTotalCommits() {
|
public int getTotalCommits() {
|
||||||
return total_commits;
|
return total_commits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets base commit.
|
||||||
|
*
|
||||||
|
* @return the base commit
|
||||||
|
*/
|
||||||
public Commit getBaseCommit() {
|
public Commit getBaseCommit() {
|
||||||
return base_commit;
|
return base_commit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets merge base commit.
|
||||||
|
*
|
||||||
|
* @return the merge base commit
|
||||||
|
*/
|
||||||
public Commit getMergeBaseCommit() {
|
public Commit getMergeBaseCommit() {
|
||||||
return merge_base_commit;
|
return merge_base_commit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an array of commits.
|
* Gets an array of commits.
|
||||||
|
*
|
||||||
* @return A copy of the array being stored in the class.
|
* @return A copy of the array being stored in the class.
|
||||||
*/
|
*/
|
||||||
public Commit[] getCommits() {
|
public Commit[] getCommits() {
|
||||||
@@ -74,9 +130,10 @@ public class GHCompare {
|
|||||||
System.arraycopy(commits, 0, newValue, 0, commits.length);
|
System.arraycopy(commits, 0, newValue, 0, commits.length);
|
||||||
return newValue;
|
return newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an array of commits.
|
* Gets an array of commits.
|
||||||
|
*
|
||||||
* @return A copy of the array being stored in the class.
|
* @return A copy of the array being stored in the class.
|
||||||
*/
|
*/
|
||||||
public GHCommit.File[] getFiles() {
|
public GHCommit.File[] getFiles() {
|
||||||
@@ -85,6 +142,13 @@ public class GHCompare {
|
|||||||
return newValue;
|
return newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap gh compare.
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
* the owner
|
||||||
|
* @return the gh compare
|
||||||
|
*/
|
||||||
public GHCompare wrap(GHRepository owner) {
|
public GHCompare wrap(GHRepository owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
for (Commit commit : commits) {
|
for (Commit commit : commits) {
|
||||||
@@ -96,71 +160,126 @@ public class GHCompare {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare commits had a child commit element with additional details we want to capture.
|
* Compare commits had a child commit element with additional details we want to capture. This extenstion of
|
||||||
* This extenstion of GHCommit provides that.
|
* GHCommit provides that.
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD"},
|
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD" },
|
||||||
justification = "JSON API")
|
justification = "JSON API")
|
||||||
public static class Commit extends GHCommit {
|
public static class Commit extends GHCommit {
|
||||||
|
|
||||||
private InnerCommit commit;
|
private InnerCommit commit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets commit.
|
||||||
|
*
|
||||||
|
* @return the commit
|
||||||
|
*/
|
||||||
public InnerCommit getCommit() {
|
public InnerCommit getCommit() {
|
||||||
return commit;
|
return commit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type InnerCommit.
|
||||||
|
*/
|
||||||
public static class InnerCommit {
|
public static class InnerCommit {
|
||||||
private String url, sha, message;
|
private String url, sha, message;
|
||||||
private User author, committer;
|
private User author, committer;
|
||||||
private Tree tree;
|
private Tree tree;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets sha.
|
||||||
|
*
|
||||||
|
* @return the sha
|
||||||
|
*/
|
||||||
public String getSha() {
|
public String getSha() {
|
||||||
return sha;
|
return sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets message.
|
||||||
|
*
|
||||||
|
* @return the message
|
||||||
|
*/
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@WithBridgeMethods(value=User.class,castRequired=true)
|
/**
|
||||||
|
* Gets author.
|
||||||
|
*
|
||||||
|
* @return the author
|
||||||
|
*/
|
||||||
|
@WithBridgeMethods(value = User.class, castRequired = true)
|
||||||
public GitUser getAuthor() {
|
public GitUser getAuthor() {
|
||||||
return author;
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
@WithBridgeMethods(value=User.class,castRequired=true)
|
/**
|
||||||
|
* Gets committer.
|
||||||
|
*
|
||||||
|
* @return the committer
|
||||||
|
*/
|
||||||
|
@WithBridgeMethods(value = User.class, castRequired = true)
|
||||||
public GitUser getCommitter() {
|
public GitUser getCommitter() {
|
||||||
return committer;
|
return committer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets tree.
|
||||||
|
*
|
||||||
|
* @return the tree
|
||||||
|
*/
|
||||||
public Tree getTree() {
|
public Tree getTree() {
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Tree.
|
||||||
|
*/
|
||||||
public static class Tree {
|
public static class Tree {
|
||||||
private String url, sha;
|
private String url, sha;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets sha.
|
||||||
|
*
|
||||||
|
* @return the sha
|
||||||
|
*/
|
||||||
public String getSha() {
|
public String getSha() {
|
||||||
return sha;
|
return sha;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The type User.
|
||||||
|
*
|
||||||
* @deprecated use {@link GitUser} instead.
|
* @deprecated use {@link GitUser} instead.
|
||||||
*/
|
*/
|
||||||
public static class User extends GitUser {
|
public static class User extends GitUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The enum Status.
|
||||||
|
*/
|
||||||
public static enum Status {
|
public static enum Status {
|
||||||
behind, ahead, identical, diverged
|
behind, ahead, identical, diverged
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,22 +2,24 @@ package org.kohsuke.github;
|
|||||||
|
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.codec.binary.Base64InputStream;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Content of a repository.
|
* A Content of a repository.
|
||||||
*
|
*
|
||||||
* @author Alexandre COLLIGNON
|
* @author Alexandre COLLIGNON
|
||||||
* @see GHRepository#getFileContent(String)
|
* @see GHRepository#getFileContent(String) GHRepository#getFileContent(String)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({ "UnusedDeclaration" })
|
||||||
public class GHContent {
|
public class GHContent implements Refreshable {
|
||||||
/*
|
/*
|
||||||
In normal use of this class, repository field is set via wrap(),
|
* In normal use of this class, repository field is set via wrap(), but in the code search API, there's a nested
|
||||||
but in the code search API, there's a nested 'repository' field that gets populated from JSON.
|
* 'repository' field that gets populated from JSON.
|
||||||
*/
|
*/
|
||||||
private GHRepository repository;
|
private GHRepository repository;
|
||||||
|
|
||||||
@@ -31,34 +33,69 @@ public class GHContent {
|
|||||||
private String path;
|
private String path;
|
||||||
private String content;
|
private String content;
|
||||||
private String url; // this is the API url
|
private String url; // this is the API url
|
||||||
private String git_url; // this is the Blob url
|
private String git_url; // this is the Blob url
|
||||||
private String html_url; // this is the UI
|
private String html_url; // this is the UI
|
||||||
private String download_url;
|
private String download_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets owner.
|
||||||
|
*
|
||||||
|
* @return the owner
|
||||||
|
*/
|
||||||
public GHRepository getOwner() {
|
public GHRepository getOwner() {
|
||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets type.
|
||||||
|
*
|
||||||
|
* @return the type
|
||||||
|
*/
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets encoding.
|
||||||
|
*
|
||||||
|
* @return the encoding
|
||||||
|
*/
|
||||||
public String getEncoding() {
|
public String getEncoding() {
|
||||||
return encoding;
|
return encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets size.
|
||||||
|
*
|
||||||
|
* @return the size
|
||||||
|
*/
|
||||||
public long getSize() {
|
public long getSize() {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets sha.
|
||||||
|
*
|
||||||
|
* @return the sha
|
||||||
|
*/
|
||||||
public String getSha() {
|
public String getSha() {
|
||||||
return sha;
|
return sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets name.
|
||||||
|
*
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets path.
|
||||||
|
*
|
||||||
|
* @return the path
|
||||||
|
*/
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
@@ -67,12 +104,13 @@ public class GHContent {
|
|||||||
* Retrieve the decoded content that is stored at this location.
|
* Retrieve the decoded content that is stored at this location.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Due to the nature of GitHub's API, you're not guaranteed that
|
* Due to the nature of GitHub's API, you're not guaranteed that the content will already be populated, so this may
|
||||||
* the content will already be populated, so this may trigger
|
* trigger network activity, and can throw an IOException.
|
||||||
* network activity, and can throw an IOException.
|
|
||||||
*
|
*
|
||||||
* @deprecated
|
* @return the content
|
||||||
* Use {@link #read()}
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @deprecated Use {@link #read()}
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings("DM_DEFAULT_ENCODING")
|
@SuppressFBWarnings("DM_DEFAULT_ENCODING")
|
||||||
public String getContent() throws IOException {
|
public String getContent() throws IOException {
|
||||||
@@ -83,28 +121,42 @@ public class GHContent {
|
|||||||
* Retrieve the base64-encoded content that is stored at this location.
|
* Retrieve the base64-encoded content that is stored at this location.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Due to the nature of GitHub's API, you're not guaranteed that
|
* Due to the nature of GitHub's API, you're not guaranteed that the content will already be populated, so this may
|
||||||
* the content will already be populated, so this may trigger
|
* trigger network activity, and can throw an IOException.
|
||||||
* network activity, and can throw an IOException.
|
|
||||||
*
|
*
|
||||||
* @deprecated
|
* @return the encoded content
|
||||||
* Use {@link #read()}
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @deprecated Use {@link #read()}
|
||||||
*/
|
*/
|
||||||
public String getEncodedContent() throws IOException {
|
public String getEncodedContent() throws IOException {
|
||||||
if (content!=null)
|
refresh(content);
|
||||||
return content;
|
return content;
|
||||||
else
|
|
||||||
return Base64.encodeBase64String(IOUtils.toByteArray(read()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets git url.
|
||||||
|
*
|
||||||
|
* @return the git url
|
||||||
|
*/
|
||||||
public String getGitUrl() {
|
public String getGitUrl() {
|
||||||
return git_url;
|
return git_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets html url.
|
||||||
|
*
|
||||||
|
* @return the html url
|
||||||
|
*/
|
||||||
public String getHtmlUrl() {
|
public String getHtmlUrl() {
|
||||||
return html_url;
|
return html_url;
|
||||||
}
|
}
|
||||||
@@ -112,85 +164,159 @@ public class GHContent {
|
|||||||
/**
|
/**
|
||||||
* Retrieves the actual content stored here.
|
* Retrieves the actual content stored here.
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* Retrieves the actual bytes of the blob.
|
||||||
|
*
|
||||||
|
* @return the input stream
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public InputStream read() throws IOException {
|
public InputStream read() throws IOException {
|
||||||
// if the download link is encoded with a token on the query string, the default behavior of POST will fail
|
refresh(content);
|
||||||
return new Requester(root).method("GET").asStream(getDownloadUrl());
|
if (encoding.equals("base64")) {
|
||||||
|
try {
|
||||||
|
return new Base64InputStream(new ByteArrayInputStream(content.getBytes("US-ASCII")), false);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new AssertionError(e); // US-ASCII is mandatory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new UnsupportedOperationException("Unrecognized encoding: " + encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL to retrieve the raw content of the file. Null if this is a directory.
|
* URL to retrieve the raw content of the file. Null if this is a directory.
|
||||||
|
*
|
||||||
|
* @return the download url
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public String getDownloadUrl() throws IOException {
|
public String getDownloadUrl() throws IOException {
|
||||||
populate();
|
refresh(download_url);
|
||||||
return download_url;
|
return download_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is file boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isFile() {
|
public boolean isFile() {
|
||||||
return "file".equals(type);
|
return "file".equals(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is directory boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isDirectory() {
|
public boolean isDirectory() {
|
||||||
return "dir".equals(type);
|
return "dir".equals(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fully populate the data by retrieving missing data.
|
* Fully populate the data by retrieving missing data.
|
||||||
*
|
* <p>
|
||||||
* Depending on the original API call where this object is created, it may not contain everything.
|
* Depending on the original API call where this object is created, it may not contain everything.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
protected synchronized void populate() throws IOException {
|
protected synchronized void populate() throws IOException {
|
||||||
if (download_url!=null) return; // already populated
|
|
||||||
root.retrieve().to(url, this);
|
root.retrieve().to(url, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List immediate children of this directory.
|
* List immediate children of this directory.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHContent> listDirectoryContent() throws IOException {
|
public PagedIterable<GHContent> listDirectoryContent() throws IOException {
|
||||||
if (!isDirectory())
|
if (!isDirectory())
|
||||||
throw new IllegalStateException(path+" is not a directory");
|
throw new IllegalStateException(path + " is not a directory");
|
||||||
|
|
||||||
return new PagedIterable<GHContent>() {
|
return root.retrieve().asPagedIterable(url, GHContent[].class, item -> item.wrap(repository));
|
||||||
public PagedIterator<GHContent> _iterator(int pageSize) {
|
|
||||||
return new PagedIterator<GHContent>(root.retrieve().asIterator(url, GHContent[].class, pageSize)) {
|
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHContent[] page) {
|
|
||||||
GHContent.wrap(page, repository);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update gh content update response.
|
||||||
|
*
|
||||||
|
* @param newContent
|
||||||
|
* the new content
|
||||||
|
* @param commitMessage
|
||||||
|
* the commit message
|
||||||
|
* @return the gh content update response
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
@SuppressFBWarnings("DM_DEFAULT_ENCODING")
|
@SuppressFBWarnings("DM_DEFAULT_ENCODING")
|
||||||
public GHContentUpdateResponse update(String newContent, String commitMessage) throws IOException {
|
public GHContentUpdateResponse update(String newContent, String commitMessage) throws IOException {
|
||||||
return update(newContent.getBytes(), commitMessage, null);
|
return update(newContent.getBytes(), commitMessage, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update gh content update response.
|
||||||
|
*
|
||||||
|
* @param newContent
|
||||||
|
* the new content
|
||||||
|
* @param commitMessage
|
||||||
|
* the commit message
|
||||||
|
* @param branch
|
||||||
|
* the branch
|
||||||
|
* @return the gh content update response
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
@SuppressFBWarnings("DM_DEFAULT_ENCODING")
|
@SuppressFBWarnings("DM_DEFAULT_ENCODING")
|
||||||
public GHContentUpdateResponse update(String newContent, String commitMessage, String branch) throws IOException {
|
public GHContentUpdateResponse update(String newContent, String commitMessage, String branch) throws IOException {
|
||||||
return update(newContent.getBytes(), commitMessage, branch);
|
return update(newContent.getBytes(), commitMessage, branch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update gh content update response.
|
||||||
|
*
|
||||||
|
* @param newContentBytes
|
||||||
|
* the new content bytes
|
||||||
|
* @param commitMessage
|
||||||
|
* the commit message
|
||||||
|
* @return the gh content update response
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessage) throws IOException {
|
public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessage) throws IOException {
|
||||||
return update(newContentBytes, commitMessage, null);
|
return update(newContentBytes, commitMessage, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessage, String branch) throws IOException {
|
/**
|
||||||
|
* Update gh content update response.
|
||||||
|
*
|
||||||
|
* @param newContentBytes
|
||||||
|
* the new content bytes
|
||||||
|
* @param commitMessage
|
||||||
|
* the commit message
|
||||||
|
* @param branch
|
||||||
|
* the branch
|
||||||
|
* @return the gh content update response
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessage, String branch)
|
||||||
|
throws IOException {
|
||||||
String encodedContent = Base64.encodeBase64String(newContentBytes);
|
String encodedContent = Base64.encodeBase64String(newContentBytes);
|
||||||
|
|
||||||
Requester requester = new Requester(root)
|
Requester requester = new Requester(root).with("path", path)
|
||||||
.with("path", path)
|
.with("message", commitMessage)
|
||||||
.with("message", commitMessage)
|
.with("sha", sha)
|
||||||
.with("sha", sha)
|
.with("content", encodedContent)
|
||||||
.with("content", encodedContent)
|
.method("PUT");
|
||||||
.method("PUT");
|
|
||||||
|
|
||||||
if (branch != null) {
|
if (branch != null) {
|
||||||
requester.with("branch", branch);
|
requester.with("branch", branch);
|
||||||
}
|
}
|
||||||
|
|
||||||
GHContentUpdateResponse response = requester.to(getApiRoute(), GHContentUpdateResponse.class);
|
GHContentUpdateResponse response = requester.to(getApiRoute(repository, path), GHContentUpdateResponse.class);
|
||||||
|
|
||||||
response.getContent().wrap(repository);
|
response.getContent().wrap(repository);
|
||||||
response.getCommit().wrapUp(repository);
|
response.getCommit().wrapUp(repository);
|
||||||
@@ -199,29 +325,48 @@ public class GHContent {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete gh content update response.
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
* the message
|
||||||
|
* @return the gh content update response
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHContentUpdateResponse delete(String message) throws IOException {
|
public GHContentUpdateResponse delete(String message) throws IOException {
|
||||||
return delete(message, null);
|
return delete(message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete gh content update response.
|
||||||
|
*
|
||||||
|
* @param commitMessage
|
||||||
|
* the commit message
|
||||||
|
* @param branch
|
||||||
|
* the branch
|
||||||
|
* @return the gh content update response
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHContentUpdateResponse delete(String commitMessage, String branch) throws IOException {
|
public GHContentUpdateResponse delete(String commitMessage, String branch) throws IOException {
|
||||||
Requester requester = new Requester(root)
|
Requester requester = new Requester(root).with("path", path)
|
||||||
.with("path", path)
|
.with("message", commitMessage)
|
||||||
.with("message", commitMessage)
|
.with("sha", sha)
|
||||||
.with("sha", sha)
|
.method("DELETE");
|
||||||
.method("DELETE");
|
|
||||||
|
|
||||||
if (branch != null) {
|
if (branch != null) {
|
||||||
requester.with("branch", branch);
|
requester.with("branch", branch);
|
||||||
}
|
}
|
||||||
|
|
||||||
GHContentUpdateResponse response = requester.to(getApiRoute(), GHContentUpdateResponse.class);
|
GHContentUpdateResponse response = requester.to(getApiRoute(repository, path), GHContentUpdateResponse.class);
|
||||||
|
|
||||||
response.getCommit().wrapUp(repository);
|
response.getCommit().wrapUp(repository);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getApiRoute() {
|
static String getApiRoute(GHRepository repository, String path) {
|
||||||
return "/repos/" + repository.getOwnerName() + "/" + repository.getName() + "/contents/" + path;
|
return repository.getApiTailUrl("contents/" + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
GHContent wrap(GHRepository owner) {
|
GHContent wrap(GHRepository owner) {
|
||||||
@@ -229,18 +374,37 @@ public class GHContent {
|
|||||||
this.root = owner.root;
|
this.root = owner.root;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
GHContent wrap(GitHub root) {
|
GHContent wrap(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
if (repository!=null)
|
if (repository != null)
|
||||||
repository.wrap(root);
|
repository.wrap(root);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap gh content [ ].
|
||||||
|
*
|
||||||
|
* @param contents
|
||||||
|
* the contents
|
||||||
|
* @param repository
|
||||||
|
* the repository
|
||||||
|
* @return the gh content [ ]
|
||||||
|
*/
|
||||||
public static GHContent[] wrap(GHContent[] contents, GHRepository repository) {
|
public static GHContent[] wrap(GHContent[] contents, GHRepository repository) {
|
||||||
for (GHContent unwrappedContent : contents) {
|
for (GHContent unwrappedContent : contents) {
|
||||||
unwrappedContent.wrap(repository);
|
unwrappedContent.wrap(repository);
|
||||||
}
|
}
|
||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fully populate the data by retrieving missing data.
|
||||||
|
*
|
||||||
|
* Depending on the original API call where this object is created, it may not contain everything.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void refresh() throws IOException {
|
||||||
|
root.retrieve().to(url, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import java.io.UnsupportedEncodingException;
|
|||||||
* Call various methods to build up parameters, then call {@link #commit()} to make the change effective.
|
* Call various methods to build up parameters, then call {@link #commit()} to make the change effective.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHRepository#createContent()
|
* @see GHRepository#createContent() GHRepository#createContent()
|
||||||
*/
|
*/
|
||||||
public final class GHContentBuilder {
|
public final class GHContentBuilder {
|
||||||
private final GHRepository repo;
|
private final GHRepository repo;
|
||||||
@@ -24,31 +24,62 @@ public final class GHContentBuilder {
|
|||||||
this.req = new Requester(repo.root).method("PUT");
|
this.req = new Requester(repo.root).method("PUT");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path gh content builder.
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
|
* the path
|
||||||
|
* @return the gh content builder
|
||||||
|
*/
|
||||||
public GHContentBuilder path(String path) {
|
public GHContentBuilder path(String path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
req.with("path",path);
|
req.with("path", path);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Branch gh content builder.
|
||||||
|
*
|
||||||
|
* @param branch
|
||||||
|
* the branch
|
||||||
|
* @return the gh content builder
|
||||||
|
*/
|
||||||
public GHContentBuilder branch(String branch) {
|
public GHContentBuilder branch(String branch) {
|
||||||
req.with("branch", branch);
|
req.with("branch", branch);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used when updating (but not creating a new content) to specify
|
* Used when updating (but not creating a new content) to specify Thetblob SHA of the file being replaced.
|
||||||
* Thetblob SHA of the file being replaced.
|
*
|
||||||
|
* @param sha
|
||||||
|
* the sha
|
||||||
|
* @return the gh content builder
|
||||||
*/
|
*/
|
||||||
public GHContentBuilder sha(String sha) {
|
public GHContentBuilder sha(String sha) {
|
||||||
req.with("sha", sha);
|
req.with("sha", sha);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content gh content builder.
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
* the content
|
||||||
|
* @return the gh content builder
|
||||||
|
*/
|
||||||
public GHContentBuilder content(byte[] content) {
|
public GHContentBuilder content(byte[] content) {
|
||||||
req.with("content", Base64.encodeBase64String(content));
|
req.with("content", Base64.encodeBase64String(content));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content gh content builder.
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
* the content
|
||||||
|
* @return the gh content builder
|
||||||
|
*/
|
||||||
public GHContentBuilder content(String content) {
|
public GHContentBuilder content(String content) {
|
||||||
try {
|
try {
|
||||||
return content(content.getBytes("UTF-8"));
|
return content(content.getBytes("UTF-8"));
|
||||||
@@ -57,6 +88,13 @@ public final class GHContentBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Message gh content builder.
|
||||||
|
*
|
||||||
|
* @param commitMessage
|
||||||
|
* the commit message
|
||||||
|
* @return the gh content builder
|
||||||
|
*/
|
||||||
public GHContentBuilder message(String commitMessage) {
|
public GHContentBuilder message(String commitMessage) {
|
||||||
req.with("message", commitMessage);
|
req.with("message", commitMessage);
|
||||||
return this;
|
return this;
|
||||||
@@ -64,9 +102,13 @@ public final class GHContentBuilder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Commits a new content.
|
* Commits a new content.
|
||||||
|
*
|
||||||
|
* @return the gh content update response
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHContentUpdateResponse commit() throws IOException {
|
public GHContentUpdateResponse commit() throws IOException {
|
||||||
GHContentUpdateResponse response = req.to(repo.getApiTailUrl("contents/" + path), GHContentUpdateResponse.class);
|
GHContentUpdateResponse response = req.to(GHContent.getApiRoute(repo, path), GHContentUpdateResponse.class);
|
||||||
|
|
||||||
response.getContent().wrap(repo);
|
response.getContent().wrap(repo);
|
||||||
response.getCommit().wrapUp(repo);
|
response.getCommit().wrapUp(repo);
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ package org.kohsuke.github;
|
|||||||
* Search code for {@link GHContent}.
|
* Search code for {@link GHContent}.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GitHub#searchContent()
|
* @see GitHub#searchContent() GitHub#searchContent()
|
||||||
*/
|
*/
|
||||||
public class GHContentSearchBuilder extends GHSearchBuilder<GHContent> {
|
public class GHContentSearchBuilder extends GHSearchBuilder<GHContent> {
|
||||||
/*package*/ GHContentSearchBuilder(GitHub root) {
|
GHContentSearchBuilder(GitHub root) {
|
||||||
super(root,ContentSearchResult.class);
|
super(root, ContentSearchResult.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,48 +19,110 @@ public class GHContentSearchBuilder extends GHSearchBuilder<GHContent> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In gh content search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh content search builder
|
||||||
|
*/
|
||||||
public GHContentSearchBuilder in(String v) {
|
public GHContentSearchBuilder in(String v) {
|
||||||
return q("in:"+v);
|
return q("in:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Language gh content search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh content search builder
|
||||||
|
*/
|
||||||
public GHContentSearchBuilder language(String v) {
|
public GHContentSearchBuilder language(String v) {
|
||||||
return q("language:"+v);
|
return q("language:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fork gh content search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh content search builder
|
||||||
|
*/
|
||||||
public GHContentSearchBuilder fork(String v) {
|
public GHContentSearchBuilder fork(String v) {
|
||||||
return q("fork:"+v);
|
return q("fork:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Size gh content search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh content search builder
|
||||||
|
*/
|
||||||
public GHContentSearchBuilder size(String v) {
|
public GHContentSearchBuilder size(String v) {
|
||||||
return q("size:"+v);
|
return q("size:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path gh content search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh content search builder
|
||||||
|
*/
|
||||||
public GHContentSearchBuilder path(String v) {
|
public GHContentSearchBuilder path(String v) {
|
||||||
return q("path:"+v);
|
return q("path:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filename gh content search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh content search builder
|
||||||
|
*/
|
||||||
public GHContentSearchBuilder filename(String v) {
|
public GHContentSearchBuilder filename(String v) {
|
||||||
return q("filename:"+v);
|
return q("filename:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extension gh content search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh content search builder
|
||||||
|
*/
|
||||||
public GHContentSearchBuilder extension(String v) {
|
public GHContentSearchBuilder extension(String v) {
|
||||||
return q("extension:"+v);
|
return q("extension:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User gh content search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh content search builder
|
||||||
|
*/
|
||||||
public GHContentSearchBuilder user(String v) {
|
public GHContentSearchBuilder user(String v) {
|
||||||
return q("user:"+v);
|
return q("user:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repo gh content search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh content search builder
|
||||||
|
*/
|
||||||
public GHContentSearchBuilder repo(String v) {
|
public GHContentSearchBuilder repo(String v) {
|
||||||
return q("repo:"+v);
|
return q("repo:" + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ContentSearchResult extends SearchResult<GHContent> {
|
private static class ContentSearchResult extends SearchResult<GHContent> {
|
||||||
private GHContent[] items;
|
private GHContent[] items;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/*package*/ GHContent[] getItems(GitHub root) {
|
GHContent[] getItems(GitHub root) {
|
||||||
for (GHContent item : items)
|
for (GHContent item : items)
|
||||||
item.wrap(root);
|
item.wrap(root);
|
||||||
return items;
|
return items;
|
||||||
|
|||||||
@@ -1,17 +1,26 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The response that is returned when updating
|
* The response that is returned when updating repository content.
|
||||||
* repository content.
|
*/
|
||||||
**/
|
|
||||||
public class GHContentUpdateResponse {
|
public class GHContentUpdateResponse {
|
||||||
private GHContent content;
|
private GHContent content;
|
||||||
private GHCommit commit;
|
private GHCommit commit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets content.
|
||||||
|
*
|
||||||
|
* @return the content
|
||||||
|
*/
|
||||||
public GHContent getContent() {
|
public GHContent getContent() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets commit.
|
||||||
|
*
|
||||||
|
* @return the commit
|
||||||
|
*/
|
||||||
public GHCommit getCommit() {
|
public GHCommit getCommit() {
|
||||||
return commit;
|
return commit;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,13 @@ package org.kohsuke.github;
|
|||||||
* @see <a href="https://developer.github.com/v3/licenses/#get-a-repositorys-license">documentation</a>
|
* @see <a href="https://developer.github.com/v3/licenses/#get-a-repositorys-license">documentation</a>
|
||||||
* @see GHRepository#getLicense()
|
* @see GHRepository#getLicense()
|
||||||
*/
|
*/
|
||||||
@Preview @Deprecated
|
|
||||||
class GHContentWithLicense extends GHContent {
|
class GHContentWithLicense extends GHContent {
|
||||||
GHLicense license;
|
GHLicense license;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
GHContentWithLicense wrap(GHRepository owner) {
|
GHContentWithLicense wrap(GHRepository owner) {
|
||||||
super.wrap(owner);
|
super.wrap(owner);
|
||||||
if (license!=null)
|
if (license != null)
|
||||||
license.wrap(owner.root);
|
license.wrap(owner.root);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,123 +13,187 @@ public class GHCreateRepositoryBuilder {
|
|||||||
protected final Requester builder;
|
protected final Requester builder;
|
||||||
private final String apiUrlTail;
|
private final String apiUrlTail;
|
||||||
|
|
||||||
/*package*/ GHCreateRepositoryBuilder(GitHub root, String apiUrlTail, String name) {
|
GHCreateRepositoryBuilder(GitHub root, String apiUrlTail, String name) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
this.apiUrlTail = apiUrlTail;
|
this.apiUrlTail = apiUrlTail;
|
||||||
this.builder = new Requester(root);
|
this.builder = new Requester(root);
|
||||||
this.builder.with("name",name);
|
this.builder.with("name", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description for repository
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
* description of repository
|
||||||
|
* @return a builder to continue with building
|
||||||
|
*/
|
||||||
public GHCreateRepositoryBuilder description(String description) {
|
public GHCreateRepositoryBuilder description(String description) {
|
||||||
this.builder.with("description",description);
|
this.builder.with("description", description);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Homepage for repository
|
||||||
|
*
|
||||||
|
* @param homepage
|
||||||
|
* homepage of repository
|
||||||
|
* @return a builder to continue with building
|
||||||
|
*/
|
||||||
public GHCreateRepositoryBuilder homepage(URL homepage) {
|
public GHCreateRepositoryBuilder homepage(URL homepage) {
|
||||||
return homepage(homepage.toExternalForm());
|
return homepage(homepage.toExternalForm());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Homepage for repository
|
||||||
|
*
|
||||||
|
* @param homepage
|
||||||
|
* homepage of repository
|
||||||
|
* @return a builder to continue with building
|
||||||
|
*/
|
||||||
public GHCreateRepositoryBuilder homepage(String homepage) {
|
public GHCreateRepositoryBuilder homepage(String homepage) {
|
||||||
this.builder.with("homepage",homepage);
|
this.builder.with("homepage", homepage);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a private repository
|
* Creates a private repository
|
||||||
|
*
|
||||||
|
* @param enabled
|
||||||
|
* private if true
|
||||||
|
* @return a builder to continue with building
|
||||||
*/
|
*/
|
||||||
public GHCreateRepositoryBuilder private_(boolean b) {
|
public GHCreateRepositoryBuilder private_(boolean enabled) {
|
||||||
this.builder.with("private",b);
|
this.builder.with("private", enabled);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables issue tracker
|
* Enables issue tracker
|
||||||
|
*
|
||||||
|
* @param enabled
|
||||||
|
* true if enabled
|
||||||
|
* @return a builder to continue with building
|
||||||
*/
|
*/
|
||||||
public GHCreateRepositoryBuilder issues(boolean b) {
|
public GHCreateRepositoryBuilder issues(boolean enabled) {
|
||||||
this.builder.with("has_issues",b);
|
this.builder.with("has_issues", enabled);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables wiki
|
* Enables wiki
|
||||||
|
*
|
||||||
|
* @param enabled
|
||||||
|
* true if enabled
|
||||||
|
* @return a builder to continue with building
|
||||||
*/
|
*/
|
||||||
public GHCreateRepositoryBuilder wiki(boolean b) {
|
public GHCreateRepositoryBuilder wiki(boolean enabled) {
|
||||||
this.builder.with("has_wiki",b);
|
this.builder.with("has_wiki", enabled);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables downloads
|
* Enables downloads
|
||||||
|
*
|
||||||
|
* @param enabled
|
||||||
|
* true if enabled
|
||||||
|
* @return a builder to continue with building
|
||||||
*/
|
*/
|
||||||
public GHCreateRepositoryBuilder downloads(boolean b) {
|
public GHCreateRepositoryBuilder downloads(boolean enabled) {
|
||||||
this.builder.with("has_downloads",b);
|
this.builder.with("has_downloads", enabled);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If true, create an initial commit with empty README.
|
* If true, create an initial commit with empty README.
|
||||||
|
*
|
||||||
|
* @param enabled
|
||||||
|
* true if enabled
|
||||||
|
* @return a builder to continue with building
|
||||||
*/
|
*/
|
||||||
public GHCreateRepositoryBuilder autoInit(boolean b) {
|
public GHCreateRepositoryBuilder autoInit(boolean enabled) {
|
||||||
this.builder.with("auto_init",b);
|
this.builder.with("auto_init", enabled);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow or disallow squash-merging pull requests.
|
* Allow or disallow squash-merging pull requests.
|
||||||
|
*
|
||||||
|
* @param enabled
|
||||||
|
* true if enabled
|
||||||
|
* @return a builder to continue with building
|
||||||
*/
|
*/
|
||||||
public GHCreateRepositoryBuilder allowSquashMerge(boolean b) {
|
public GHCreateRepositoryBuilder allowSquashMerge(boolean enabled) {
|
||||||
this.builder.with("allow_squash_merge",b);
|
this.builder.with("allow_squash_merge", enabled);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow or disallow merging pull requests with a merge commit.
|
* Allow or disallow merging pull requests with a merge commit.
|
||||||
|
*
|
||||||
|
* @param enabled
|
||||||
|
* true if enabled
|
||||||
|
* @return a builder to continue with building
|
||||||
*/
|
*/
|
||||||
public GHCreateRepositoryBuilder allowMergeCommit(boolean b) {
|
public GHCreateRepositoryBuilder allowMergeCommit(boolean enabled) {
|
||||||
this.builder.with("allow_merge_commit",b);
|
this.builder.with("allow_merge_commit", enabled);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow or disallow rebase-merging pull requests.
|
* Allow or disallow rebase-merging pull requests.
|
||||||
|
*
|
||||||
|
* @param enabled
|
||||||
|
* true if enabled
|
||||||
|
* @return a builder to continue with building
|
||||||
*/
|
*/
|
||||||
public GHCreateRepositoryBuilder allowRebaseMerge(boolean b) {
|
public GHCreateRepositoryBuilder allowRebaseMerge(boolean enabled) {
|
||||||
this.builder.with("allow_rebase_merge",b);
|
this.builder.with("allow_rebase_merge", enabled);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a default .gitignore
|
* Creates a default .gitignore
|
||||||
*
|
*
|
||||||
* See https://developer.github.com/v3/repos/#create
|
* @param language
|
||||||
|
* template to base the ignore file on
|
||||||
|
* @return a builder to continue with building See https://developer.github.com/v3/repos/#create
|
||||||
*/
|
*/
|
||||||
public GHCreateRepositoryBuilder gitignoreTemplate(String language) {
|
public GHCreateRepositoryBuilder gitignoreTemplate(String language) {
|
||||||
this.builder.with("gitignore_template",language);
|
this.builder.with("gitignore_template", language);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Desired license template to apply
|
* Desired license template to apply
|
||||||
*
|
*
|
||||||
* See https://developer.github.com/v3/repos/#create
|
* @param license
|
||||||
|
* template to base the license file on
|
||||||
|
* @return a builder to continue with building See https://developer.github.com/v3/repos/#create
|
||||||
*/
|
*/
|
||||||
public GHCreateRepositoryBuilder licenseTemplate(String license) {
|
public GHCreateRepositoryBuilder licenseTemplate(String license) {
|
||||||
this.builder.with("license_template",license);
|
this.builder.with("license_template", license);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The team that gets granted access to this repository. Only valid for creating a repository in
|
* The team that gets granted access to this repository. Only valid for creating a repository in an organization.
|
||||||
* an organization.
|
*
|
||||||
|
* @param team
|
||||||
|
* team to grant access to
|
||||||
|
* @return a builder to continue with building
|
||||||
*/
|
*/
|
||||||
public GHCreateRepositoryBuilder team(GHTeam team) {
|
public GHCreateRepositoryBuilder team(GHTeam team) {
|
||||||
if (team!=null)
|
if (team != null)
|
||||||
this.builder.with("team_id",team.getId());
|
this.builder.with("team_id", team.getId());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a repository with all the parameters.
|
* Creates a repository with all the parameters.
|
||||||
|
*
|
||||||
|
* @return the gh repository
|
||||||
|
* @throws IOException
|
||||||
|
* if repsitory cannot be created
|
||||||
*/
|
*/
|
||||||
public GHRepository create() throws IOException {
|
public GHRepository create() throws IOException {
|
||||||
return builder.method("POST").to(apiUrlTail, GHRepository.class).wrap(root);
|
return builder.method("POST").to(apiUrlTail, GHRepository.class).wrap(root);
|
||||||
|
|||||||
@@ -4,43 +4,85 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type GHDeployKey.
|
||||||
|
*/
|
||||||
public class GHDeployKey {
|
public class GHDeployKey {
|
||||||
|
|
||||||
protected String url, key, title;
|
protected String url, key, title;
|
||||||
protected boolean verified;
|
protected boolean verified;
|
||||||
protected int id;
|
protected long id;
|
||||||
private GHRepository owner;
|
private GHRepository owner;
|
||||||
|
|
||||||
public int getId() {
|
/**
|
||||||
|
* Gets id.
|
||||||
|
*
|
||||||
|
* @return the id
|
||||||
|
*/
|
||||||
|
public long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets key.
|
||||||
|
*
|
||||||
|
* @return the key
|
||||||
|
*/
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets title.
|
||||||
|
*
|
||||||
|
* @return the title
|
||||||
|
*/
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is verified boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isVerified() {
|
public boolean isVerified() {
|
||||||
return verified;
|
return verified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap gh deploy key.
|
||||||
|
*
|
||||||
|
* @param repo
|
||||||
|
* the repo
|
||||||
|
* @return the gh deploy key
|
||||||
|
*/
|
||||||
public GHDeployKey wrap(GHRepository repo) {
|
public GHDeployKey wrap(GHRepository repo) {
|
||||||
this.owner = repo;
|
this.owner = repo;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this).append("title",title).append("id",id).append("key",key).toString();
|
return new ToStringBuilder(this).append("title", title).append("id", id).append("key", key).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(owner.root).method("DELETE").to(String.format("/repos/%s/%s/keys/%d", owner.getOwnerName(), owner.getName(), id));
|
new Requester(owner.root).method("DELETE")
|
||||||
|
.to(String.format("/repos/%s/%s/keys/%d", owner.getOwnerName(), owner.getName(), id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ import java.net.URL;
|
|||||||
* Represents a deployment
|
* Represents a deployment
|
||||||
*
|
*
|
||||||
* @see <a href="https://developer.github.com/v3/repos/deployments/">documentation</a>
|
* @see <a href="https://developer.github.com/v3/repos/deployments/">documentation</a>
|
||||||
* @see GHRepository#listDeployments(String, String, String, String)
|
* @see GHRepository#listDeployments(String, String, String, String) GHRepository#listDeployments(String, String,
|
||||||
* @see GHRepository#getDeployment(long)
|
* String, String)
|
||||||
|
* @see GHRepository#getDeployment(long) GHRepository#getDeployment(long)
|
||||||
*/
|
*/
|
||||||
public class GHDeployment extends GHObject {
|
public class GHDeployment extends GHObject {
|
||||||
private GHRepository owner;
|
private GHRepository owner;
|
||||||
@@ -23,38 +24,85 @@ public class GHDeployment extends GHObject {
|
|||||||
protected String repository_url;
|
protected String repository_url;
|
||||||
protected GHUser creator;
|
protected GHUser creator;
|
||||||
|
|
||||||
|
|
||||||
GHDeployment wrap(GHRepository owner) {
|
GHDeployment wrap(GHRepository owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.root = owner.root;
|
this.root = owner.root;
|
||||||
if(creator != null) creator.wrapUp(root);
|
if (creator != null)
|
||||||
|
creator.wrapUp(root);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets statuses url.
|
||||||
|
*
|
||||||
|
* @return the statuses url
|
||||||
|
*/
|
||||||
public URL getStatusesUrl() {
|
public URL getStatusesUrl() {
|
||||||
return GitHub.parseURL(statuses_url);
|
return GitHub.parseURL(statuses_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets repository url.
|
||||||
|
*
|
||||||
|
* @return the repository url
|
||||||
|
*/
|
||||||
public URL getRepositoryUrl() {
|
public URL getRepositoryUrl() {
|
||||||
return GitHub.parseURL(repository_url);
|
return GitHub.parseURL(repository_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets task.
|
||||||
|
*
|
||||||
|
* @return the task
|
||||||
|
*/
|
||||||
public String getTask() {
|
public String getTask() {
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets payload.
|
||||||
|
*
|
||||||
|
* @return the payload
|
||||||
|
*/
|
||||||
public String getPayload() {
|
public String getPayload() {
|
||||||
return (String) payload;
|
return (String) payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets environment.
|
||||||
|
*
|
||||||
|
* @return the environment
|
||||||
|
*/
|
||||||
public String getEnvironment() {
|
public String getEnvironment() {
|
||||||
return environment;
|
return environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets creator.
|
||||||
|
*
|
||||||
|
* @return the creator
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHUser getCreator() throws IOException {
|
public GHUser getCreator() throws IOException {
|
||||||
return root.intern(creator);
|
return root.intern(creator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets ref.
|
||||||
|
*
|
||||||
|
* @return the ref
|
||||||
|
*/
|
||||||
public String getRef() {
|
public String getRef() {
|
||||||
return ref;
|
return ref;
|
||||||
}
|
}
|
||||||
public String getSha(){
|
|
||||||
|
/**
|
||||||
|
* Gets sha.
|
||||||
|
*
|
||||||
|
* @return the sha
|
||||||
|
*/
|
||||||
|
public String getSha() {
|
||||||
return sha;
|
return sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,22 +114,24 @@ public class GHDeployment extends GHObject {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create status gh deployment status builder.
|
||||||
|
*
|
||||||
|
* @param state
|
||||||
|
* the state
|
||||||
|
* @return the gh deployment status builder
|
||||||
|
*/
|
||||||
public GHDeploymentStatusBuilder createStatus(GHDeploymentState state) {
|
public GHDeploymentStatusBuilder createStatus(GHDeploymentState state) {
|
||||||
return new GHDeploymentStatusBuilder(owner,id,state);
|
return new GHDeploymentStatusBuilder(owner, id, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List statuses paged iterable.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
*/
|
||||||
public PagedIterable<GHDeploymentStatus> listStatuses() {
|
public PagedIterable<GHDeploymentStatus> listStatuses() {
|
||||||
return new PagedIterable<GHDeploymentStatus>() {
|
return root.retrieve().asPagedIterable(statuses_url, GHDeploymentStatus[].class, item -> item.wrap(owner));
|
||||||
public PagedIterator<GHDeploymentStatus> _iterator(int pageSize) {
|
|
||||||
return new PagedIterator<GHDeploymentStatus>(root.retrieve().asIterator(statuses_url, GHDeploymentStatus[].class, pageSize)) {
|
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHDeploymentStatus[] page) {
|
|
||||||
for (GHDeploymentStatus c : page)
|
|
||||||
c.wrap(owner);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,53 +3,130 @@ package org.kohsuke.github;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
//Based on https://developer.github.com/v3/repos/deployments/#create-a-deployment
|
/**
|
||||||
|
* The type GHDeploymentBuilder.
|
||||||
|
*/
|
||||||
|
// Based on https://developer.github.com/v3/repos/deployments/#create-a-deployment
|
||||||
public class GHDeploymentBuilder {
|
public class GHDeploymentBuilder {
|
||||||
private final GHRepository repo;
|
private final GHRepository repo;
|
||||||
private final Requester builder;
|
private final Requester builder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Gh deployment builder.
|
||||||
|
*
|
||||||
|
* @param repo
|
||||||
|
* the repo
|
||||||
|
*/
|
||||||
public GHDeploymentBuilder(GHRepository repo) {
|
public GHDeploymentBuilder(GHRepository repo) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.builder = new Requester(repo.root);
|
this.builder = new Requester(repo.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Gh deployment builder.
|
||||||
|
*
|
||||||
|
* @param repo
|
||||||
|
* the repo
|
||||||
|
* @param ref
|
||||||
|
* the ref
|
||||||
|
*/
|
||||||
public GHDeploymentBuilder(GHRepository repo, String ref) {
|
public GHDeploymentBuilder(GHRepository repo, String ref) {
|
||||||
this(repo);
|
this(repo);
|
||||||
ref(ref);
|
ref(ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ref gh deployment builder.
|
||||||
|
*
|
||||||
|
* @param branch
|
||||||
|
* the branch
|
||||||
|
* @return the gh deployment builder
|
||||||
|
*/
|
||||||
public GHDeploymentBuilder ref(String branch) {
|
public GHDeploymentBuilder ref(String branch) {
|
||||||
builder.with("ref",branch);
|
builder.with("ref", branch);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task gh deployment builder.
|
||||||
|
*
|
||||||
|
* @param task
|
||||||
|
* the task
|
||||||
|
* @return the gh deployment builder
|
||||||
|
*/
|
||||||
public GHDeploymentBuilder task(String task) {
|
public GHDeploymentBuilder task(String task) {
|
||||||
builder.with("task",task);
|
builder.with("task", task);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto merge gh deployment builder.
|
||||||
|
*
|
||||||
|
* @param autoMerge
|
||||||
|
* the auto merge
|
||||||
|
* @return the gh deployment builder
|
||||||
|
*/
|
||||||
public GHDeploymentBuilder autoMerge(boolean autoMerge) {
|
public GHDeploymentBuilder autoMerge(boolean autoMerge) {
|
||||||
builder.with("auto_merge",autoMerge);
|
builder.with("auto_merge", autoMerge);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Required contexts gh deployment builder.
|
||||||
|
*
|
||||||
|
* @param requiredContexts
|
||||||
|
* the required contexts
|
||||||
|
* @return the gh deployment builder
|
||||||
|
*/
|
||||||
public GHDeploymentBuilder requiredContexts(List<String> requiredContexts) {
|
public GHDeploymentBuilder requiredContexts(List<String> requiredContexts) {
|
||||||
builder.with("required_contexts",requiredContexts);
|
builder.with("required_contexts", requiredContexts);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payload gh deployment builder.
|
||||||
|
*
|
||||||
|
* @param payload
|
||||||
|
* the payload
|
||||||
|
* @return the gh deployment builder
|
||||||
|
*/
|
||||||
public GHDeploymentBuilder payload(String payload) {
|
public GHDeploymentBuilder payload(String payload) {
|
||||||
builder.with("payload",payload);
|
builder.with("payload", payload);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Environment gh deployment builder.
|
||||||
|
*
|
||||||
|
* @param environment
|
||||||
|
* the environment
|
||||||
|
* @return the gh deployment builder
|
||||||
|
*/
|
||||||
public GHDeploymentBuilder environment(String environment) {
|
public GHDeploymentBuilder environment(String environment) {
|
||||||
builder.with("environment",environment);
|
builder.with("environment", environment);
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public GHDeploymentBuilder description(String description) {
|
|
||||||
builder.with("description",description);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description gh deployment builder.
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
* the description
|
||||||
|
* @return the gh deployment builder
|
||||||
|
*/
|
||||||
|
public GHDeploymentBuilder description(String description) {
|
||||||
|
builder.with("description", description);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create gh deployment.
|
||||||
|
*
|
||||||
|
* @return the gh deployment
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHDeployment create() throws IOException {
|
public GHDeployment create() throws IOException {
|
||||||
return builder.to(repo.getApiTailUrl("deployments"),GHDeployment.class).wrap(repo);
|
return builder.to(repo.getApiTailUrl("deployments"), GHDeployment.class).wrap(repo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ package org.kohsuke.github;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type GHDeploymentStatus.
|
||||||
|
*/
|
||||||
public class GHDeploymentStatus extends GHObject {
|
public class GHDeploymentStatus extends GHObject {
|
||||||
private GHRepository owner;
|
private GHRepository owner;
|
||||||
private GitHub root;
|
private GitHub root;
|
||||||
@@ -12,24 +15,54 @@ public class GHDeploymentStatus extends GHObject {
|
|||||||
protected String target_url;
|
protected String target_url;
|
||||||
protected String deployment_url;
|
protected String deployment_url;
|
||||||
protected String repository_url;
|
protected String repository_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap gh deployment status.
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
* the owner
|
||||||
|
* @return the gh deployment status
|
||||||
|
*/
|
||||||
public GHDeploymentStatus wrap(GHRepository owner) {
|
public GHDeploymentStatus wrap(GHRepository owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.root = owner.root;
|
this.root = owner.root;
|
||||||
if(creator != null) creator.wrapUp(root);
|
if (creator != null)
|
||||||
|
creator.wrapUp(root);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets target url.
|
||||||
|
*
|
||||||
|
* @return the target url
|
||||||
|
*/
|
||||||
public URL getTargetUrl() {
|
public URL getTargetUrl() {
|
||||||
return GitHub.parseURL(target_url);
|
return GitHub.parseURL(target_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets deployment url.
|
||||||
|
*
|
||||||
|
* @return the deployment url
|
||||||
|
*/
|
||||||
public URL getDeploymentUrl() {
|
public URL getDeploymentUrl() {
|
||||||
return GitHub.parseURL(deployment_url);
|
return GitHub.parseURL(deployment_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets repository url.
|
||||||
|
*
|
||||||
|
* @return the repository url
|
||||||
|
*/
|
||||||
public URL getRepositoryUrl() {
|
public URL getRepositoryUrl() {
|
||||||
return GitHub.parseURL(repository_url);
|
return GitHub.parseURL(repository_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets state.
|
||||||
|
*
|
||||||
|
* @return the state
|
||||||
|
*/
|
||||||
public GHDeploymentState getState() {
|
public GHDeploymentState getState() {
|
||||||
return GHDeploymentState.valueOf(state.toUpperCase(Locale.ENGLISH));
|
return GHDeploymentState.valueOf(state.toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import java.io.IOException;
|
|||||||
/**
|
/**
|
||||||
* Creates a new deployment status.
|
* Creates a new deployment status.
|
||||||
*
|
*
|
||||||
* @see
|
* @see GHDeployment#createStatus(GHDeploymentState) GHDeployment#createStatus(GHDeploymentState)
|
||||||
* GHDeployment#createStatus(GHDeploymentState)
|
|
||||||
*/
|
*/
|
||||||
public class GHDeploymentStatusBuilder {
|
public class GHDeploymentStatusBuilder {
|
||||||
private final Requester builder;
|
private final Requester builder;
|
||||||
@@ -14,31 +13,60 @@ public class GHDeploymentStatusBuilder {
|
|||||||
private long deploymentId;
|
private long deploymentId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* Instantiates a new Gh deployment status builder.
|
||||||
* Use {@link GHDeployment#createStatus(GHDeploymentState)}
|
*
|
||||||
|
* @param repo
|
||||||
|
* the repo
|
||||||
|
* @param deploymentId
|
||||||
|
* the deployment id
|
||||||
|
* @param state
|
||||||
|
* the state
|
||||||
|
* @deprecated Use {@link GHDeployment#createStatus(GHDeploymentState)}
|
||||||
*/
|
*/
|
||||||
public GHDeploymentStatusBuilder(GHRepository repo, int deploymentId, GHDeploymentState state) {
|
public GHDeploymentStatusBuilder(GHRepository repo, int deploymentId, GHDeploymentState state) {
|
||||||
this(repo,(long)deploymentId,state);
|
this(repo, (long) deploymentId, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHDeploymentStatusBuilder(GHRepository repo, long deploymentId, GHDeploymentState state) {
|
GHDeploymentStatusBuilder(GHRepository repo, long deploymentId, GHDeploymentState state) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.deploymentId = deploymentId;
|
this.deploymentId = deploymentId;
|
||||||
this.builder = new Requester(repo.root);
|
this.builder = new Requester(repo.root);
|
||||||
this.builder.with("state",state);
|
this.builder.with("state", state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description gh deployment status builder.
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
* the description
|
||||||
|
* @return the gh deployment status builder
|
||||||
|
*/
|
||||||
public GHDeploymentStatusBuilder description(String description) {
|
public GHDeploymentStatusBuilder description(String description) {
|
||||||
this.builder.with("description",description);
|
this.builder.with("description", description);
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GHDeploymentStatusBuilder targetUrl(String targetUrl) {
|
|
||||||
this.builder.with("target_url",targetUrl);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Target url gh deployment status builder.
|
||||||
|
*
|
||||||
|
* @param targetUrl
|
||||||
|
* the target url
|
||||||
|
* @return the gh deployment status builder
|
||||||
|
*/
|
||||||
|
public GHDeploymentStatusBuilder targetUrl(String targetUrl) {
|
||||||
|
this.builder.with("target_url", targetUrl);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create gh deployment status.
|
||||||
|
*
|
||||||
|
* @return the gh deployment status
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHDeploymentStatus create() throws IOException {
|
public GHDeploymentStatus create() throws IOException {
|
||||||
return builder.to(repo.getApiTailUrl("deployments/"+deploymentId+"/statuses"),GHDeploymentStatus.class).wrap(repo);
|
return builder.to(repo.getApiTailUrl("deployments/" + deploymentId + "/statuses"), GHDeploymentStatus.class)
|
||||||
|
.wrap(repo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,36 +25,51 @@ package org.kohsuke.github;
|
|||||||
|
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an email of GitHub.
|
* Represents an email of GitHub.
|
||||||
*
|
*
|
||||||
* @author Kelly Campbell
|
* @author Kelly Campbell
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
|
@SuppressFBWarnings(
|
||||||
"NP_UNWRITTEN_FIELD", "NP_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD"}, justification = "JSON API")
|
value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
|
||||||
|
"NP_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD" },
|
||||||
|
justification = "JSON API")
|
||||||
public class GHEmail {
|
public class GHEmail {
|
||||||
|
|
||||||
protected String email;
|
protected String email;
|
||||||
protected boolean primary;
|
protected boolean primary;
|
||||||
protected boolean verified;
|
protected boolean verified;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets email.
|
||||||
|
*
|
||||||
|
* @return the email
|
||||||
|
*/
|
||||||
public String getEmail() {
|
public String getEmail() {
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is primary boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isPrimary() {
|
public boolean isPrimary() {
|
||||||
return primary;
|
return primary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is verified boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isVerified() {
|
public boolean isVerified() {
|
||||||
return verified;
|
return verified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Email:"+email;
|
return "Email:" + email;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public enum GHEvent {
|
|||||||
GOLLUM,
|
GOLLUM,
|
||||||
INSTALLATION,
|
INSTALLATION,
|
||||||
INSTALLATION_REPOSITORIES,
|
INSTALLATION_REPOSITORIES,
|
||||||
|
INTEGRATION_INSTALLATION_REPOSITORIES,
|
||||||
|
CHECK_SUITE,
|
||||||
ISSUE_COMMENT,
|
ISSUE_COMMENT,
|
||||||
ISSUES,
|
ISSUES,
|
||||||
LABEL,
|
LABEL,
|
||||||
@@ -42,7 +44,11 @@ public enum GHEvent {
|
|||||||
PULL_REQUEST_REVIEW_COMMENT,
|
PULL_REQUEST_REVIEW_COMMENT,
|
||||||
PUSH,
|
PUSH,
|
||||||
RELEASE,
|
RELEASE,
|
||||||
REPOSITORY, // only valid for org hooks
|
REPOSITORY, // only
|
||||||
|
// valid
|
||||||
|
// for
|
||||||
|
// org
|
||||||
|
// hooks
|
||||||
STATUS,
|
STATUS,
|
||||||
TEAM,
|
TEAM,
|
||||||
TEAM_ADD,
|
TEAM_ADD,
|
||||||
@@ -53,12 +59,12 @@ public enum GHEvent {
|
|||||||
*/
|
*/
|
||||||
ALL;
|
ALL;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns GitHub's internal representation of this event.
|
* Returns GitHub's internal representation of this event.
|
||||||
*/
|
*/
|
||||||
String symbol() {
|
String symbol() {
|
||||||
if (this==ALL) return "*";
|
if (this == ALL)
|
||||||
|
return "*";
|
||||||
return name().toLowerCase(Locale.ENGLISH);
|
return name().toLowerCase(Locale.ENGLISH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,73 +30,118 @@ public class GHEventInfo {
|
|||||||
/**
|
/**
|
||||||
* Inside the event JSON model, GitHub uses a slightly different format.
|
* Inside the event JSON model, GitHub uses a slightly different format.
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
|
@SuppressFBWarnings(
|
||||||
"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, justification = "JSON API")
|
value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
|
||||||
|
"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
|
||||||
|
justification = "JSON API")
|
||||||
public static class GHEventRepository {
|
public static class GHEventRepository {
|
||||||
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
|
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
|
||||||
private int id;
|
private long id;
|
||||||
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
|
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
|
||||||
private String url; // repository API URL
|
private String url; // repository API URL
|
||||||
private String name; // owner/repo
|
private String name; // owner/repo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets type.
|
||||||
|
*
|
||||||
|
* @return the type
|
||||||
|
*/
|
||||||
public GHEvent getType() {
|
public GHEvent getType() {
|
||||||
String t = type;
|
String t = type;
|
||||||
if (t.endsWith("Event")) t=t.substring(0,t.length()-5);
|
if (t.endsWith("Event"))
|
||||||
|
t = t.substring(0, t.length() - 5);
|
||||||
for (GHEvent e : GHEvent.values()) {
|
for (GHEvent e : GHEvent.values()) {
|
||||||
if (e.name().replace("_","").equalsIgnoreCase(t))
|
if (e.name().replace("_", "").equalsIgnoreCase(t))
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
return null; // unknown event type
|
return null; // unknown event type
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHEventInfo wrapUp(GitHub root) {
|
GHEventInfo wrapUp(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets id.
|
||||||
|
*
|
||||||
|
* @return the id
|
||||||
|
*/
|
||||||
public long getId() {
|
public long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets created at.
|
||||||
|
*
|
||||||
|
* @return the created at
|
||||||
|
*/
|
||||||
public Date getCreatedAt() {
|
public Date getCreatedAt() {
|
||||||
return GitHub.parseDate(created_at);
|
return GitHub.parseDate(created_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repository where the change was made.
|
* Gets repository.
|
||||||
|
*
|
||||||
|
* @return Repository where the change was made.
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
|
@SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
|
||||||
justification = "The field comes from JSON deserialization")
|
justification = "The field comes from JSON deserialization")
|
||||||
public GHRepository getRepository() throws IOException {
|
public GHRepository getRepository() throws IOException {
|
||||||
return root.getRepository(repo.name);
|
return root.getRepository(repo.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
|
/**
|
||||||
|
* Gets actor.
|
||||||
|
*
|
||||||
|
* @return the {@link GHUser} actor for this event.
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
|
*/
|
||||||
|
@SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
|
||||||
justification = "The field comes from JSON deserialization")
|
justification = "The field comes from JSON deserialization")
|
||||||
public GHUser getActor() throws IOException {
|
public GHUser getActor() throws IOException {
|
||||||
return root.getUser(actor.getLogin());
|
return root.getUser(actor.getLogin());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quick way to just get the actor of the login.
|
* Gets actor login.
|
||||||
|
*
|
||||||
|
* @return the login of the actor.
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
*/
|
*/
|
||||||
public String getActorLogin() throws IOException {
|
public String getActorLogin() throws IOException {
|
||||||
return actor.getLogin();
|
return actor.getLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
|
/**
|
||||||
|
* Gets organization.
|
||||||
|
*
|
||||||
|
* @return the organization
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
@SuppressFBWarnings(value = { "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
|
||||||
justification = "The field comes from JSON deserialization")
|
justification = "The field comes from JSON deserialization")
|
||||||
public GHOrganization getOrganization() throws IOException {
|
public GHOrganization getOrganization() throws IOException {
|
||||||
return (org==null || org.getLogin()==null) ? null : root.getOrganization(org.getLogin());
|
return (org == null || org.getLogin() == null) ? null : root.getOrganization(org.getLogin());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the payload.
|
* Retrieves the payload.
|
||||||
*
|
*
|
||||||
|
* @param <T>
|
||||||
|
* the type parameter
|
||||||
* @param type
|
* @param type
|
||||||
* Specify one of the {@link GHEventPayload} subtype that defines a type-safe access to the payload.
|
* Specify one of the {@link GHEventPayload} subtype that defines a type-safe access to the payload. This
|
||||||
* This must match the {@linkplain #getType() event type}.
|
* must match the {@linkplain #getType() event type}.
|
||||||
|
* @return parsed event payload
|
||||||
|
* @throws IOException
|
||||||
|
* if payload cannot be parsed
|
||||||
*/
|
*/
|
||||||
public <T extends GHEventPayload> T getPayload(Class<T> type) throws IOException {
|
public <T extends GHEventPayload> T getPayload(Class<T> type) throws IOException {
|
||||||
T v = GitHub.MAPPER.readValue(payload.traverse(), type);
|
T v = GitHub.MAPPER.readValue(payload.traverse(), type);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,29 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The type GHException.
|
||||||
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public class GHException extends RuntimeException {
|
public class GHException extends RuntimeException {
|
||||||
|
/**
|
||||||
|
* Instantiates a new Gh exception.
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
* the message
|
||||||
|
*/
|
||||||
public GHException(String message) {
|
public GHException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Gh exception.
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
* the message
|
||||||
|
* @param cause
|
||||||
|
* the cause
|
||||||
|
*/
|
||||||
public GHException(String message, Throwable cause) {
|
public GHException(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,41 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import javax.annotation.CheckForNull;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.CheckForNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request/responce contains useful metadata.
|
* Request/responce contains useful metadata. Custom exception allows store info for next diagnostics.
|
||||||
* Custom exception allows store info for next diagnostics.
|
|
||||||
*
|
*
|
||||||
* @author Kanstantsin Shautsou
|
* @author Kanstantsin Shautsou
|
||||||
*/
|
*/
|
||||||
public class GHFileNotFoundException extends FileNotFoundException {
|
public class GHFileNotFoundException extends FileNotFoundException {
|
||||||
protected Map<String, List<String>> responseHeaderFields;
|
protected Map<String, List<String>> responseHeaderFields;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Gh file not found exception.
|
||||||
|
*/
|
||||||
public GHFileNotFoundException() {
|
public GHFileNotFoundException() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Gh file not found exception.
|
||||||
|
*
|
||||||
|
* @param s
|
||||||
|
* the s
|
||||||
|
*/
|
||||||
public GHFileNotFoundException(String s) {
|
public GHFileNotFoundException(String s) {
|
||||||
super(s);
|
super(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets response header fields.
|
||||||
|
*
|
||||||
|
* @return the response header fields
|
||||||
|
*/
|
||||||
@CheckForNull
|
@CheckForNull
|
||||||
public Map<String, List<String>> getResponseHeaderFields() {
|
public Map<String, List<String>> getResponseHeaderFields() {
|
||||||
return responseHeaderFields;
|
return responseHeaderFields;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -13,14 +14,14 @@ import java.util.Map.Entry;
|
|||||||
* Gist
|
* Gist
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHUser#listGists()
|
* @see GHUser#listGists() GHUser#listGists()
|
||||||
* @see GitHub#getGist(String)
|
* @see GitHub#getGist(String) GitHub#getGist(String)
|
||||||
* @see GitHub#createGist()
|
* @see GitHub#createGist() GitHub#createGist()
|
||||||
* @see <a href="https://developer.github.com/v3/gists/">documentation</a>
|
* @see <a href="https://developer.github.com/v3/gists/">documentation</a>
|
||||||
*/
|
*/
|
||||||
public class GHGist extends GHObject {
|
public class GHGist extends GHObject {
|
||||||
/*package almost final*/ GHUser owner;
|
/* package almost final */ GHUser owner;
|
||||||
/*package almost final*/ GitHub root;
|
/* package almost final */ GitHub root;
|
||||||
|
|
||||||
private String forks_url, commits_url, id, git_pull_url, git_push_url, html_url;
|
private String forks_url, commits_url, id, git_pull_url, git_push_url, html_url;
|
||||||
|
|
||||||
@@ -33,30 +34,51 @@ public class GHGist extends GHObject {
|
|||||||
|
|
||||||
private String comments_url;
|
private String comments_url;
|
||||||
|
|
||||||
private Map<String,GHGistFile> files = new HashMap<String, GHGistFile>();
|
private Map<String, GHGistFile> files = new HashMap<String, GHGistFile>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User that owns this Gist.
|
* Gets owner.
|
||||||
|
*
|
||||||
|
* @return User that owns this Gist.
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHUser getOwner() throws IOException {
|
public GHUser getOwner() throws IOException {
|
||||||
return root.intern(owner);
|
return root.intern(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets forks url.
|
||||||
|
*
|
||||||
|
* @return the forks url
|
||||||
|
*/
|
||||||
public String getForksUrl() {
|
public String getForksUrl() {
|
||||||
return forks_url;
|
return forks_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets commits url.
|
||||||
|
*
|
||||||
|
* @return the commits url
|
||||||
|
*/
|
||||||
public String getCommitsUrl() {
|
public String getCommitsUrl() {
|
||||||
return commits_url;
|
return commits_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL like https://gist.github.com/gists/12345.git
|
* Gets git pull url.
|
||||||
|
*
|
||||||
|
* @return URL like https://gist.github.com/gists/12345.git
|
||||||
*/
|
*/
|
||||||
public String getGitPullUrl() {
|
public String getGitPullUrl() {
|
||||||
return git_pull_url;
|
return git_pull_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets git push url.
|
||||||
|
*
|
||||||
|
* @return the git push url
|
||||||
|
*/
|
||||||
public String getGitPushUrl() {
|
public String getGitPushUrl() {
|
||||||
return git_push_url;
|
return git_push_url;
|
||||||
}
|
}
|
||||||
@@ -65,34 +87,63 @@ public class GHGist extends GHObject {
|
|||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is public boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isPublic() {
|
public boolean isPublic() {
|
||||||
return _public;
|
return _public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets description.
|
||||||
|
*
|
||||||
|
* @return the description
|
||||||
|
*/
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets comment count.
|
||||||
|
*
|
||||||
|
* @return the comment count
|
||||||
|
*/
|
||||||
public int getCommentCount() {
|
public int getCommentCount() {
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API URL of listing comments.
|
* Gets comments url.
|
||||||
|
*
|
||||||
|
* @return API URL of listing comments.
|
||||||
*/
|
*/
|
||||||
public String getCommentsUrl() {
|
public String getCommentsUrl() {
|
||||||
return comments_url;
|
return comments_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets file.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @return the file
|
||||||
|
*/
|
||||||
public GHGistFile getFile(String name) {
|
public GHGistFile getFile(String name) {
|
||||||
return files.get(name);
|
return files.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String,GHGistFile> getFiles() {
|
/**
|
||||||
|
* Gets files.
|
||||||
|
*
|
||||||
|
* @return the files
|
||||||
|
*/
|
||||||
|
public Map<String, GHGistFile> getFiles() {
|
||||||
return Collections.unmodifiableMap(files);
|
return Collections.unmodifiableMap(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHGist wrapUp(GHUser owner) {
|
GHGist wrapUp(GHUser owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.root = owner.root;
|
this.root = owner.root;
|
||||||
wrapUp();
|
wrapUp();
|
||||||
@@ -100,10 +151,10 @@ public class GHGist extends GHObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used when caller obtains {@link GHGist} without knowing its owner.
|
* Used when caller obtains {@link GHGist} without knowing its owner. A partially constructed owner object is
|
||||||
* A partially constructed owner object is interned.
|
* interned.
|
||||||
*/
|
*/
|
||||||
/*package*/ GHGist wrapUp(GitHub root) {
|
GHGist wrapUp(GitHub root) {
|
||||||
this.owner = root.getUser(owner);
|
this.owner = root.getUser(owner);
|
||||||
this.root = root;
|
this.root = root;
|
||||||
wrapUp();
|
wrapUp();
|
||||||
@@ -115,54 +166,93 @@ public class GHGist extends GHObject {
|
|||||||
e.getValue().fileName = e.getKey();
|
e.getValue().fileName = e.getKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getApiTailUrl(String tail) {
|
String getApiTailUrl(String tail) {
|
||||||
return "/gists/" + id + '/' + tail;
|
String result = "/gists/" + id;
|
||||||
|
if (!StringUtils.isBlank(tail)) {
|
||||||
|
result += StringUtils.prependIfMissing(tail, "/");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Star.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void star() throws IOException {
|
public void star() throws IOException {
|
||||||
new Requester(root).method("PUT").to(getApiTailUrl("star"));
|
new Requester(root).method("PUT").to(getApiTailUrl("star"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unstar.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void unstar() throws IOException {
|
public void unstar() throws IOException {
|
||||||
new Requester(root).method("DELETE").to(getApiTailUrl("star"));
|
new Requester(root).method("DELETE").to(getApiTailUrl("star"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is starred boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public boolean isStarred() throws IOException {
|
public boolean isStarred() throws IOException {
|
||||||
return root.retrieve().asHttpStatusCode(getApiTailUrl("star"))/100==2;
|
return root.retrieve().asHttpStatusCode(getApiTailUrl("star")) / 100 == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forks this gist into your own.
|
* Forks this gist into your own.
|
||||||
|
*
|
||||||
|
* @return the gh gist
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHGist fork() throws IOException {
|
public GHGist fork() throws IOException {
|
||||||
return new Requester(root).to(getApiTailUrl("forks"),GHGist.class).wrapUp(root);
|
return new Requester(root).to(getApiTailUrl("forks"), GHGist.class).wrapUp(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List forks paged iterable.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
*/
|
||||||
public PagedIterable<GHGist> listForks() {
|
public PagedIterable<GHGist> listForks() {
|
||||||
return new PagedIterable<GHGist>() {
|
return root.retrieve().asPagedIterable(getApiTailUrl("forks"), GHGist[].class, item -> item.wrapUp(root));
|
||||||
public PagedIterator<GHGist> _iterator(int pageSize) {
|
|
||||||
return new PagedIterator<GHGist>(root.retrieve().asIterator(getApiTailUrl("forks"), GHGist[].class, pageSize)) {
|
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHGist[] page) {
|
|
||||||
for (GHGist c : page)
|
|
||||||
c.wrapUp(root);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes this gist.
|
* Deletes this gist.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(root).method("DELETE").to("/gists/" + id);
|
new Requester(root).method("DELETE").to("/gists/" + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates this gist via a builder.
|
||||||
|
*
|
||||||
|
* @return the gh gist updater
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHGistUpdater update() throws IOException {
|
||||||
|
return new GHGistUpdater(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o)
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
if (o == null || getClass() != o.getClass())
|
||||||
|
return false;
|
||||||
GHGist ghGist = (GHGist) o;
|
GHGist ghGist = (GHGist) o;
|
||||||
return id.equals(ghGist.id);
|
return id.equals(ghGist.id);
|
||||||
|
|
||||||
@@ -172,4 +262,10 @@ public class GHGist extends GHObject {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return id.hashCode();
|
return id.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GHGist wrap(GHUser owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
this.root = owner.root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,30 +8,56 @@ import java.util.LinkedHashMap;
|
|||||||
* Builder pattern for creating a new Gist.
|
* Builder pattern for creating a new Gist.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GitHub#createGist()
|
* @see GitHub#createGist() GitHub#createGist()
|
||||||
*/
|
*/
|
||||||
public class GHGistBuilder {
|
public class GHGistBuilder {
|
||||||
private final GitHub root;
|
private final GitHub root;
|
||||||
private final Requester req;
|
private final Requester req;
|
||||||
private final LinkedHashMap<String,Object> files = new LinkedHashMap<String, Object>();
|
private final LinkedHashMap<String, Object> files = new LinkedHashMap<String, Object>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Gh gist builder.
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* the root
|
||||||
|
*/
|
||||||
public GHGistBuilder(GitHub root) {
|
public GHGistBuilder(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
req = new Requester(root);
|
req = new Requester(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description gh gist builder.
|
||||||
|
*
|
||||||
|
* @param desc
|
||||||
|
* the desc
|
||||||
|
* @return the gh gist builder
|
||||||
|
*/
|
||||||
public GHGistBuilder description(String desc) {
|
public GHGistBuilder description(String desc) {
|
||||||
req.with("description",desc);
|
req.with("description", desc);
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GHGistBuilder public_(boolean v) {
|
|
||||||
req.with("public",v);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new file.
|
* Public gh gist builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh gist builder
|
||||||
|
*/
|
||||||
|
public GHGistBuilder public_(boolean v) {
|
||||||
|
req.with("public", v);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File gh gist builder.
|
||||||
|
*
|
||||||
|
* @param fileName
|
||||||
|
* the file name
|
||||||
|
* @param content
|
||||||
|
* the content
|
||||||
|
* @return Adds a new file.
|
||||||
*/
|
*/
|
||||||
public GHGistBuilder file(String fileName, String content) {
|
public GHGistBuilder file(String fileName, String content) {
|
||||||
files.put(fileName, Collections.singletonMap("content", content));
|
files.put(fileName, Collections.singletonMap("content", content));
|
||||||
@@ -40,9 +66,13 @@ public class GHGistBuilder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Gist based on the parameters specified thus far.
|
* Creates a Gist based on the parameters specified thus far.
|
||||||
|
*
|
||||||
|
* @return created Gist
|
||||||
|
* @throws IOException
|
||||||
|
* if Gist cannot be created.
|
||||||
*/
|
*/
|
||||||
public GHGist create() throws IOException {
|
public GHGist create() throws IOException {
|
||||||
req._with("files",files);
|
req.with("files", files);
|
||||||
return req.to("/gists",GHGist.class).wrapUp(root);
|
return req.to("/gists", GHGist.class).wrapUp(root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,23 +4,29 @@ package org.kohsuke.github;
|
|||||||
* A file inside {@link GHGist}
|
* A file inside {@link GHGist}
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHGist#getFile(String)
|
* @see GHGist#getFile(String) GHGist#getFile(String)
|
||||||
* @see GHGist#getFiles()
|
* @see GHGist#getFiles() GHGist#getFiles()
|
||||||
*/
|
*/
|
||||||
public class GHGistFile {
|
public class GHGistFile {
|
||||||
/*package almost final*/ String fileName;
|
/* package almost final */ String fileName;
|
||||||
|
|
||||||
private int size;
|
private int size;
|
||||||
private String raw_url, type, language, content;
|
private String raw_url, type, language, content;
|
||||||
private boolean truncated;
|
private boolean truncated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets file name.
|
||||||
|
*
|
||||||
|
* @return the file name
|
||||||
|
*/
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File size in bytes.
|
* File size in bytes.
|
||||||
|
*
|
||||||
|
* @return the size
|
||||||
*/
|
*/
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return size;
|
return size;
|
||||||
@@ -28,6 +34,8 @@ public class GHGistFile {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* URL that serves this file as-is.
|
* URL that serves this file as-is.
|
||||||
|
*
|
||||||
|
* @return the raw url
|
||||||
*/
|
*/
|
||||||
public String getRawUrl() {
|
public String getRawUrl() {
|
||||||
return raw_url;
|
return raw_url;
|
||||||
@@ -35,17 +43,26 @@ public class GHGistFile {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Content type of this Gist, such as "text/plain"
|
* Content type of this Gist, such as "text/plain"
|
||||||
|
*
|
||||||
|
* @return the type
|
||||||
*/
|
*/
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets language.
|
||||||
|
*
|
||||||
|
* @return the language
|
||||||
|
*/
|
||||||
public String getLanguage() {
|
public String getLanguage() {
|
||||||
return language;
|
return language;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Content of this file.
|
* Content of this file.
|
||||||
|
*
|
||||||
|
* @return the content
|
||||||
*/
|
*/
|
||||||
public String getContent() {
|
public String getContent() {
|
||||||
return content;
|
return content;
|
||||||
@@ -53,6 +70,8 @@ public class GHGistFile {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* (?) indicates if {@link #getContent()} contains a truncated content.
|
* (?) indicates if {@link #getContent()} contains a truncated content.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
*/
|
*/
|
||||||
public boolean isTruncated() {
|
public boolean isTruncated() {
|
||||||
return truncated;
|
return truncated;
|
||||||
|
|||||||
101
src/main/java/org/kohsuke/github/GHGistUpdater.java
Normal file
101
src/main/java/org/kohsuke/github/GHGistUpdater.java
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder pattern for updating a Gist.
|
||||||
|
*
|
||||||
|
* @author Martin van Zijl
|
||||||
|
*/
|
||||||
|
public class GHGistUpdater {
|
||||||
|
private final GHGist base;
|
||||||
|
private final Requester builder;
|
||||||
|
LinkedHashMap<String, Object> files;
|
||||||
|
|
||||||
|
GHGistUpdater(GHGist base) {
|
||||||
|
this.base = base;
|
||||||
|
this.builder = new Requester(base.root);
|
||||||
|
|
||||||
|
files = new LinkedHashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add file gh gist updater.
|
||||||
|
*
|
||||||
|
* @param fileName
|
||||||
|
* the file name
|
||||||
|
* @param content
|
||||||
|
* the content
|
||||||
|
* @return the gh gist updater
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHGistUpdater addFile(String fileName, String content) throws IOException {
|
||||||
|
updateFile(fileName, content);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// // This method does not work.
|
||||||
|
// public GHGistUpdater deleteFile(String fileName) throws IOException {
|
||||||
|
// files.put(fileName, Collections.singletonMap("filename", null));
|
||||||
|
// return this;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename file gh gist updater.
|
||||||
|
*
|
||||||
|
* @param fileName
|
||||||
|
* the file name
|
||||||
|
* @param newFileName
|
||||||
|
* the new file name
|
||||||
|
* @return the gh gist updater
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHGistUpdater renameFile(String fileName, String newFileName) throws IOException {
|
||||||
|
files.put(fileName, Collections.singletonMap("filename", newFileName));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update file gh gist updater.
|
||||||
|
*
|
||||||
|
* @param fileName
|
||||||
|
* the file name
|
||||||
|
* @param content
|
||||||
|
* the content
|
||||||
|
* @return the gh gist updater
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHGistUpdater updateFile(String fileName, String content) throws IOException {
|
||||||
|
files.put(fileName, Collections.singletonMap("content", content));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description gh gist updater.
|
||||||
|
*
|
||||||
|
* @param desc
|
||||||
|
* the desc
|
||||||
|
* @return the gh gist updater
|
||||||
|
*/
|
||||||
|
public GHGistUpdater description(String desc) {
|
||||||
|
builder.with("description", desc);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the Gist based on the parameters specified thus far.
|
||||||
|
*
|
||||||
|
* @return the gh gist
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHGist update() throws IOException {
|
||||||
|
builder.with("files", files);
|
||||||
|
return builder.method("PATCH").to(base.getApiTailUrl(""), GHGist.class).wrap(base.owner);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,38 +11,66 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The type GHHook.
|
||||||
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
|
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
|
||||||
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
|
justification = "JSON API")
|
||||||
public abstract class GHHook extends GHObject {
|
public abstract class GHHook extends GHObject {
|
||||||
String name;
|
String name;
|
||||||
List<String> events;
|
List<String> events;
|
||||||
boolean active;
|
boolean active;
|
||||||
Map<String,String> config;
|
Map<String, String> config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets name.
|
||||||
|
*
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets events.
|
||||||
|
*
|
||||||
|
* @return the events
|
||||||
|
*/
|
||||||
public EnumSet<GHEvent> getEvents() {
|
public EnumSet<GHEvent> getEvents() {
|
||||||
EnumSet<GHEvent> s = EnumSet.noneOf(GHEvent.class);
|
EnumSet<GHEvent> s = EnumSet.noneOf(GHEvent.class);
|
||||||
for (String e : events) {
|
for (String e : events) {
|
||||||
if (e.equals("*")) s.add(GHEvent.ALL);
|
if (e.equals("*"))
|
||||||
else s.add(Enum.valueOf(GHEvent.class, e.toUpperCase(Locale.ENGLISH)));
|
s.add(GHEvent.ALL);
|
||||||
|
else
|
||||||
|
s.add(Enum.valueOf(GHEvent.class, e.toUpperCase(Locale.ENGLISH)));
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is active boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets config.
|
||||||
|
*
|
||||||
|
* @return the config
|
||||||
|
*/
|
||||||
public Map<String, String> getConfig() {
|
public Map<String, String> getConfig() {
|
||||||
return Collections.unmodifiableMap(config);
|
return Collections.unmodifiableMap(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Ping.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
* @see <a href="https://developer.github.com/v3/repos/hooks/#ping-a-hook">Ping hook</a>
|
* @see <a href="https://developer.github.com/v3/repos/hooks/#ping-a-hook">Ping hook</a>
|
||||||
*/
|
*/
|
||||||
public void ping() throws IOException {
|
public void ping() throws IOException {
|
||||||
@@ -51,6 +79,9 @@ public abstract class GHHook extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes this hook.
|
* Deletes this hook.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(getRoot()).method("DELETE").to(getApiRoute());
|
new Requester(getRoot()).method("DELETE").to(getApiRoute());
|
||||||
|
|||||||
@@ -16,37 +16,69 @@ class GHHooks {
|
|||||||
private final GitHub root;
|
private final GitHub root;
|
||||||
|
|
||||||
private Context(GitHub root) {
|
private Context(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets hooks.
|
||||||
|
*
|
||||||
|
* @return the hooks
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public List<GHHook> getHooks() throws IOException {
|
public List<GHHook> getHooks() throws IOException {
|
||||||
|
|
||||||
GHHook [] hookArray = root.retrieve().to(collection(),collectionClass()); // jdk/eclipse bug requires this to be on separate line
|
GHHook[] hookArray = root.retrieve().to(collection(), collectionClass()); // jdk/eclipse bug requires this
|
||||||
|
// to be on separate line
|
||||||
List<GHHook> list = new ArrayList<GHHook>(Arrays.asList(hookArray));
|
List<GHHook> list = new ArrayList<GHHook>(Arrays.asList(hookArray));
|
||||||
for (GHHook h : list)
|
for (GHHook h : list)
|
||||||
wrap(h);
|
wrap(h);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets hook.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* the id
|
||||||
|
* @return the hook
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHHook getHook(int id) throws IOException {
|
public GHHook getHook(int id) throws IOException {
|
||||||
GHHook hook = root.retrieve().to(collection() + "/" + id, clazz());
|
GHHook hook = root.retrieve().to(collection() + "/" + id, clazz());
|
||||||
return wrap(hook);
|
return wrap(hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHHook createHook(String name, Map<String, String> config, Collection<GHEvent> events, boolean active) throws IOException {
|
/**
|
||||||
|
* Create hook gh hook.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @param config
|
||||||
|
* the config
|
||||||
|
* @param events
|
||||||
|
* the events
|
||||||
|
* @param active
|
||||||
|
* the active
|
||||||
|
* @return the gh hook
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHHook createHook(String name, Map<String, String> config, Collection<GHEvent> events, boolean active)
|
||||||
|
throws IOException {
|
||||||
List<String> ea = null;
|
List<String> ea = null;
|
||||||
if (events!=null) {
|
if (events != null) {
|
||||||
ea = new ArrayList<String>();
|
ea = new ArrayList<String>();
|
||||||
for (GHEvent e : events)
|
for (GHEvent e : events)
|
||||||
ea.add(e.symbol());
|
ea.add(e.symbol());
|
||||||
}
|
}
|
||||||
|
|
||||||
GHHook hook = new Requester(root)
|
GHHook hook = new Requester(root).with("name", name)
|
||||||
.with("name", name)
|
.with("active", active)
|
||||||
.with("active", active)
|
.with("config", config)
|
||||||
._with("config", config)
|
.with("events", ea)
|
||||||
._with("events", ea)
|
.to(collection(), clazz());
|
||||||
.to(collection(), clazz());
|
|
||||||
|
|
||||||
return wrap(hook);
|
return wrap(hook);
|
||||||
}
|
}
|
||||||
@@ -87,7 +119,7 @@ class GHHooks {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
GHHook wrap(GHHook hook) {
|
GHHook wrap(GHHook hook) {
|
||||||
return ((GHRepoHook)hook).wrap(repository);
|
return ((GHRepoHook) hook).wrap(repository);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,15 +148,15 @@ class GHHooks {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
GHHook wrap(GHHook hook) {
|
GHHook wrap(GHHook hook) {
|
||||||
return ((GHOrgHook)hook).wrap(organization);
|
return ((GHOrgHook) hook).wrap(organization);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Context repoContext(GHRepository repository, GHUser owner) {
|
static Context repoContext(GHRepository repository, GHUser owner) {
|
||||||
return new RepoContext(repository, owner);
|
return new RepoContext(repository, owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Context orgContext(GHOrganization organization) {
|
static Context orgContext(GHOrganization organization) {
|
||||||
return new OrgContext(organization);
|
return new OrgContext(organization);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,41 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import javax.annotation.CheckForNull;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.CheckForNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request/responce contains useful metadata.
|
* Request/responce contains useful metadata. Custom exception allows store info for next diagnostics.
|
||||||
* Custom exception allows store info for next diagnostics.
|
|
||||||
*
|
*
|
||||||
* @author Kanstantsin Shautsou
|
* @author Kanstantsin Shautsou
|
||||||
*/
|
*/
|
||||||
public class GHIOException extends IOException {
|
public class GHIOException extends IOException {
|
||||||
protected Map<String, List<String>> responseHeaderFields;
|
protected Map<String, List<String>> responseHeaderFields;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Ghio exception.
|
||||||
|
*/
|
||||||
public GHIOException() {
|
public GHIOException() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Ghio exception.
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
* the message
|
||||||
|
*/
|
||||||
public GHIOException(String message) {
|
public GHIOException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets response header fields.
|
||||||
|
*
|
||||||
|
* @return the response header fields
|
||||||
|
*/
|
||||||
@CheckForNull
|
@CheckForNull
|
||||||
public Map<String, List<String>> getResponseHeaderFields() {
|
public Map<String, List<String>> getResponseHeaderFields() {
|
||||||
return responseHeaderFields;
|
return responseHeaderFields;
|
||||||
|
|||||||
@@ -6,13 +6,17 @@ import java.io.IOException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see GitHub#getMyInvitations()
|
* The type GHInvitation.
|
||||||
* @see GHRepository#listInvitations()
|
*
|
||||||
|
* @see GitHub#getMyInvitations() GitHub#getMyInvitations()
|
||||||
|
* @see GHRepository#listInvitations() GHRepository#listInvitations()
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
|
@SuppressFBWarnings(
|
||||||
"NP_UNWRITTEN_FIELD", "UUF_UNUSED_FIELD"}, justification = "JSON API")
|
value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
|
||||||
|
"UUF_UNUSED_FIELD" },
|
||||||
|
justification = "JSON API")
|
||||||
public class GHInvitation extends GHObject {
|
public class GHInvitation extends GHObject {
|
||||||
/*package almost final*/ GitHub root;
|
/* package almost final */ GitHub root;
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private GHRepository repository;
|
private GHRepository repository;
|
||||||
@@ -20,13 +24,16 @@ public class GHInvitation extends GHObject {
|
|||||||
private String permissions;
|
private String permissions;
|
||||||
private String html_url;
|
private String html_url;
|
||||||
|
|
||||||
/*package*/ GHInvitation wrapUp(GitHub root) {
|
GHInvitation wrapUp(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accept a repository invitation.
|
* Accept a repository invitation.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void accept() throws IOException {
|
public void accept() throws IOException {
|
||||||
root.retrieve().method("PATCH").to("/user/repository_invitations/" + id);
|
root.retrieve().method("PATCH").to("/user/repository_invitations/" + id);
|
||||||
@@ -34,6 +41,9 @@ public class GHInvitation extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Decline a repository invitation.
|
* Decline a repository invitation.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void decline() throws IOException {
|
public void decline() throws IOException {
|
||||||
root.retrieve().method("DELETE").to("/user/repository_invitations/" + id);
|
root.retrieve().method("DELETE").to("/user/repository_invitations/" + id);
|
||||||
|
|||||||
@@ -24,10 +24,9 @@
|
|||||||
|
|
||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import static org.kohsuke.github.Previews.SQUIRREL_GIRL;
|
|
||||||
|
|
||||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -35,28 +34,28 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
|
||||||
|
import static org.kohsuke.github.Previews.SQUIRREL_GIRL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an issue on GitHub.
|
* Represents an issue on GitHub.
|
||||||
*
|
*
|
||||||
* @author Eric Maupin
|
* @author Eric Maupin
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHRepository#getIssue(int)
|
* @see GHRepository#getIssue(int) GHRepository#getIssue(int)
|
||||||
* @see GitHub#searchIssues()
|
* @see GitHub#searchIssues() GitHub#searchIssues()
|
||||||
* @see GHIssueSearchBuilder
|
* @see GHIssueSearchBuilder
|
||||||
*/
|
*/
|
||||||
public class GHIssue extends GHObject implements Reactable{
|
public class GHIssue extends GHObject implements Reactable {
|
||||||
private static final String ASSIGNEES = "assignees";
|
private static final String ASSIGNEES = "assignees";
|
||||||
|
|
||||||
GitHub root;
|
GitHub root;
|
||||||
GHRepository owner;
|
GHRepository owner;
|
||||||
|
|
||||||
// API v3
|
// API v3
|
||||||
protected GHUser assignee; // not sure what this field is now that 'assignees' exist
|
protected GHUser assignee; // not sure what this field is now that 'assignees' exist
|
||||||
protected GHUser[] assignees;
|
protected GHUser[] assignees;
|
||||||
protected String state;
|
protected String state;
|
||||||
protected int number;
|
protected int number;
|
||||||
@@ -74,27 +73,34 @@ public class GHIssue extends GHObject implements Reactable{
|
|||||||
protected boolean locked;
|
protected boolean locked;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The type Label.
|
||||||
|
*
|
||||||
* @deprecated use {@link GHLabel}
|
* @deprecated use {@link GHLabel}
|
||||||
*/
|
*/
|
||||||
public static class Label extends GHLabel {
|
public static class Label extends GHLabel {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHIssue wrap(GHRepository owner) {
|
GHIssue wrap(GHRepository owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
if(milestone != null) milestone.wrap(owner);
|
if (milestone != null)
|
||||||
|
milestone.wrap(owner);
|
||||||
return wrap(owner.root);
|
return wrap(owner.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHIssue wrap(GitHub root) {
|
GHIssue wrap(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
if(assignee != null) assignee.wrapUp(root);
|
if (assignee != null)
|
||||||
if(assignees!=null) GHUser.wrap(assignees,root);
|
assignee.wrapUp(root);
|
||||||
if(user != null) user.wrapUp(root);
|
if (assignees != null)
|
||||||
if(closed_by != null) closed_by.wrapUp(root);
|
GHUser.wrap(assignees, root);
|
||||||
|
if (user != null)
|
||||||
|
user.wrapUp(root);
|
||||||
|
if (closed_by != null)
|
||||||
|
closed_by.wrapUp(root);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ static GHIssue[] wrap(GHIssue[] issues, GHRepository owner) {
|
static GHIssue[] wrap(GHIssue[] issues, GHRepository owner) {
|
||||||
for (GHIssue i : issues)
|
for (GHIssue i : issues)
|
||||||
i.wrap(owner);
|
i.wrap(owner);
|
||||||
return issues;
|
return issues;
|
||||||
@@ -102,6 +108,8 @@ public class GHIssue extends GHObject implements Reactable{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Repository to which the issue belongs.
|
* Repository to which the issue belongs.
|
||||||
|
*
|
||||||
|
* @return the repository
|
||||||
*/
|
*/
|
||||||
public GHRepository getRepository() {
|
public GHRepository getRepository() {
|
||||||
return owner;
|
return owner;
|
||||||
@@ -109,6 +117,8 @@ public class GHIssue extends GHObject implements Reactable{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The description of this pull request.
|
* The description of this pull request.
|
||||||
|
*
|
||||||
|
* @return the body
|
||||||
*/
|
*/
|
||||||
public String getBody() {
|
public String getBody() {
|
||||||
return body;
|
return body;
|
||||||
@@ -116,76 +126,128 @@ public class GHIssue extends GHObject implements Reactable{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ID.
|
* ID.
|
||||||
|
*
|
||||||
|
* @return the number
|
||||||
*/
|
*/
|
||||||
public int getNumber() {
|
public int getNumber() {
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The HTML page of this issue,
|
* The HTML page of this issue, like https://github.com/jenkinsci/jenkins/issues/100
|
||||||
* like https://github.com/jenkinsci/jenkins/issues/100
|
|
||||||
*/
|
*/
|
||||||
public URL getHtmlUrl() {
|
public URL getHtmlUrl() {
|
||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets title.
|
||||||
|
*
|
||||||
|
* @return the title
|
||||||
|
*/
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is locked boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isLocked() {
|
public boolean isLocked() {
|
||||||
return locked;
|
return locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets state.
|
||||||
|
*
|
||||||
|
* @return the state
|
||||||
|
*/
|
||||||
public GHIssueState getState() {
|
public GHIssueState getState() {
|
||||||
return Enum.valueOf(GHIssueState.class, state.toUpperCase(Locale.ENGLISH));
|
return Enum.valueOf(GHIssueState.class, state.toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets labels.
|
||||||
|
*
|
||||||
|
* @return the labels
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public Collection<GHLabel> getLabels() throws IOException {
|
public Collection<GHLabel> getLabels() throws IOException {
|
||||||
if(labels == null){
|
if (labels == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
return Collections.<GHLabel>unmodifiableList(labels);
|
return Collections.<GHLabel>unmodifiableList(labels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets closed at.
|
||||||
|
*
|
||||||
|
* @return the closed at
|
||||||
|
*/
|
||||||
public Date getClosedAt() {
|
public Date getClosedAt() {
|
||||||
return GitHub.parseDate(closed_at);
|
return GitHub.parseDate(closed_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL getApiURL(){
|
/**
|
||||||
|
* Gets api url.
|
||||||
|
*
|
||||||
|
* @return the api url
|
||||||
|
*/
|
||||||
|
public URL getApiURL() {
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lock.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void lock() throws IOException {
|
public void lock() throws IOException {
|
||||||
new Requester(root).method("PUT").to(getApiRoute()+"/lock");
|
new Requester(root).method("PUT").to(getApiRoute() + "/lock");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlock.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void unlock() throws IOException {
|
public void unlock() throws IOException {
|
||||||
new Requester(root).method("PUT").to(getApiRoute()+"/lock");
|
new Requester(root).method("PUT").to(getApiRoute() + "/lock");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the issue by adding a comment.
|
* Updates the issue by adding a comment.
|
||||||
*
|
*
|
||||||
* @return
|
* @param message
|
||||||
* Newly posted comment.
|
* the message
|
||||||
|
* @return Newly posted comment.
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
@WithBridgeMethods(void.class)
|
@WithBridgeMethods(void.class)
|
||||||
public GHIssueComment comment(String message) throws IOException {
|
public GHIssueComment comment(String message) throws IOException {
|
||||||
GHIssueComment r = new Requester(root).with("body",message).to(getIssuesApiRoute() + "/comments", GHIssueComment.class);
|
GHIssueComment r = new Requester(root).with("body", message)
|
||||||
|
.to(getIssuesApiRoute() + "/comments", GHIssueComment.class);
|
||||||
return r.wrapUp(this);
|
return r.wrapUp(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void edit(String key, Object value) throws IOException {
|
private void edit(String key, Object value) throws IOException {
|
||||||
new Requester(root)._with(key, value).method("PATCH").to(getApiRoute());
|
new Requester(root).with(key, value).method("PATCH").to(getApiRoute());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void editIssue(String key, Object value) throws IOException {
|
private void editIssue(String key, Object value) throws IOException {
|
||||||
new Requester(root)._with(key, value).method("PATCH").to(getIssuesApiRoute());
|
new Requester(root).with(key, value).method("PATCH").to(getIssuesApiRoute());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes this issue.
|
* Closes this issue.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
edit("state", "closed");
|
edit("state", "closed");
|
||||||
@@ -193,44 +255,106 @@ public class GHIssue extends GHObject implements Reactable{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Reopens this issue.
|
* Reopens this issue.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void reopen() throws IOException {
|
public void reopen() throws IOException {
|
||||||
edit("state", "open");
|
edit("state", "open");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets title.
|
||||||
|
*
|
||||||
|
* @param title
|
||||||
|
* the title
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void setTitle(String title) throws IOException {
|
public void setTitle(String title) throws IOException {
|
||||||
edit("title",title);
|
edit("title", title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets body.
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void setBody(String body) throws IOException {
|
public void setBody(String body) throws IOException {
|
||||||
edit("body",body);
|
edit("body", body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets milestone.
|
||||||
|
*
|
||||||
|
* @param milestone
|
||||||
|
* the milestone
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void setMilestone(GHMilestone milestone) throws IOException {
|
public void setMilestone(GHMilestone milestone) throws IOException {
|
||||||
edit("milestone",milestone.getNumber());
|
edit("milestone", milestone.getNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assign to.
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* the user
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void assignTo(GHUser user) throws IOException {
|
public void assignTo(GHUser user) throws IOException {
|
||||||
setAssignees(user);
|
setAssignees(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets labels.
|
||||||
|
*
|
||||||
|
* @param labels
|
||||||
|
* the labels
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void setLabels(String... labels) throws IOException {
|
public void setLabels(String... labels) throws IOException {
|
||||||
editIssue("labels",labels);
|
editIssue("labels", labels);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds labels to the issue.
|
* Adds labels to the issue.
|
||||||
*
|
*
|
||||||
* @param names Names of the label
|
* @param names
|
||||||
|
* Names of the label
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void addLabels(String... names) throws IOException {
|
public void addLabels(String... names) throws IOException {
|
||||||
_addLabels(Arrays.asList(names));
|
_addLabels(Arrays.asList(names));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add labels.
|
||||||
|
*
|
||||||
|
* @param labels
|
||||||
|
* the labels
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void addLabels(GHLabel... labels) throws IOException {
|
public void addLabels(GHLabel... labels) throws IOException {
|
||||||
addLabels(Arrays.asList(labels));
|
addLabels(Arrays.asList(labels));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add labels.
|
||||||
|
*
|
||||||
|
* @param labels
|
||||||
|
* the labels
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void addLabels(Collection<GHLabel> labels) throws IOException {
|
public void addLabels(Collection<GHLabel> labels) throws IOException {
|
||||||
_addLabels(GHLabel.toNames(labels));
|
_addLabels(GHLabel.toNames(labels));
|
||||||
}
|
}
|
||||||
@@ -251,18 +375,37 @@ public class GHIssue extends GHObject implements Reactable{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a given label by name from this issue.
|
* Remove a given label by name from this issue.
|
||||||
|
*
|
||||||
|
* @param names
|
||||||
|
* the names
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void removeLabels(String... names) throws IOException {
|
public void removeLabels(String... names) throws IOException {
|
||||||
_removeLabels(Arrays.asList(names));
|
_removeLabels(Arrays.asList(names));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see #removeLabels(String...)
|
* Remove labels.
|
||||||
|
*
|
||||||
|
* @param labels
|
||||||
|
* the labels
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @see #removeLabels(String...) #removeLabels(String...)
|
||||||
*/
|
*/
|
||||||
public void removeLabels(GHLabel... labels) throws IOException {
|
public void removeLabels(GHLabel... labels) throws IOException {
|
||||||
removeLabels(Arrays.asList(labels));
|
removeLabels(Arrays.asList(labels));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove labels.
|
||||||
|
*
|
||||||
|
* @param labels
|
||||||
|
* the labels
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void removeLabels(Collection<GHLabel> labels) throws IOException {
|
public void removeLabels(Collection<GHLabel> labels) throws IOException {
|
||||||
_removeLabels(GHLabel.toNames(labels));
|
_removeLabels(GHLabel.toNames(labels));
|
||||||
}
|
}
|
||||||
@@ -281,94 +424,170 @@ public class GHIssue extends GHObject implements Reactable{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains all the comments associated with this issue.
|
* Obtains all the comments associated with this issue.
|
||||||
*
|
*
|
||||||
* @see #listComments()
|
* @return the comments
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @see #listComments() #listComments()
|
||||||
*/
|
*/
|
||||||
public List<GHIssueComment> getComments() throws IOException {
|
public List<GHIssueComment> getComments() throws IOException {
|
||||||
return listComments().asList();
|
return listComments().asList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains all the comments associated with this issue.
|
* Obtains all the comments associated with this issue.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHIssueComment> listComments() throws IOException {
|
public PagedIterable<GHIssueComment> listComments() throws IOException {
|
||||||
return new PagedIterable<GHIssueComment>() {
|
return root.retrieve()
|
||||||
public PagedIterator<GHIssueComment> _iterator(int pageSize) {
|
.asPagedIterable(getIssuesApiRoute() + "/comments",
|
||||||
return new PagedIterator<GHIssueComment>(root.retrieve().asIterator(getIssuesApiRoute() + "/comments", GHIssueComment[].class, pageSize)) {
|
GHIssueComment[].class,
|
||||||
protected void wrapUp(GHIssueComment[] page) {
|
item -> item.wrapUp(GHIssue.this));
|
||||||
for (GHIssueComment c : page)
|
|
||||||
c.wrapUp(GHIssue.this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview @Deprecated
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public GHReaction createReaction(ReactionContent content) throws IOException {
|
public GHReaction createReaction(ReactionContent content) throws IOException {
|
||||||
return new Requester(owner.root)
|
return new Requester(owner.root).withPreview(SQUIRREL_GIRL)
|
||||||
.withPreview(SQUIRREL_GIRL)
|
|
||||||
.with("content", content.getContent())
|
.with("content", content.getContent())
|
||||||
.to(getApiRoute()+"/reactions", GHReaction.class).wrap(root);
|
.to(getApiRoute() + "/reactions", GHReaction.class)
|
||||||
|
.wrap(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview @Deprecated
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public PagedIterable<GHReaction> listReactions() {
|
public PagedIterable<GHReaction> listReactions() {
|
||||||
return new PagedIterable<GHReaction>() {
|
return owner.root.retrieve()
|
||||||
public PagedIterator<GHReaction> _iterator(int pageSize) {
|
.withPreview(SQUIRREL_GIRL)
|
||||||
return new PagedIterator<GHReaction>(owner.root.retrieve().withPreview(SQUIRREL_GIRL).asIterator(getApiRoute()+"/reactions", GHReaction[].class, pageSize)) {
|
.asPagedIterable(getApiRoute() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root));
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHReaction[] page) {
|
|
||||||
for (GHReaction c : page)
|
|
||||||
c.wrap(owner.root);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add assignees.
|
||||||
|
*
|
||||||
|
* @param assignees
|
||||||
|
* the assignees
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void addAssignees(GHUser... assignees) throws IOException {
|
public void addAssignees(GHUser... assignees) throws IOException {
|
||||||
addAssignees(Arrays.asList(assignees));
|
addAssignees(Arrays.asList(assignees));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add assignees.
|
||||||
|
*
|
||||||
|
* @param assignees
|
||||||
|
* the assignees
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void addAssignees(Collection<GHUser> assignees) throws IOException {
|
public void addAssignees(Collection<GHUser> assignees) throws IOException {
|
||||||
root.retrieve().method("POST").withLogins(ASSIGNEES,assignees).to(getIssuesApiRoute()+"/assignees",this);
|
root.retrieve()
|
||||||
|
.method("POST")
|
||||||
|
.with(ASSIGNEES, getLogins(assignees))
|
||||||
|
.to(getIssuesApiRoute() + "/assignees", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets assignees.
|
||||||
|
*
|
||||||
|
* @param assignees
|
||||||
|
* the assignees
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void setAssignees(GHUser... assignees) throws IOException {
|
public void setAssignees(GHUser... assignees) throws IOException {
|
||||||
setAssignees(Arrays.asList(assignees));
|
setAssignees(Arrays.asList(assignees));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets assignees.
|
||||||
|
*
|
||||||
|
* @param assignees
|
||||||
|
* the assignees
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void setAssignees(Collection<GHUser> assignees) throws IOException {
|
public void setAssignees(Collection<GHUser> assignees) throws IOException {
|
||||||
new Requester(root).withLogins(ASSIGNEES, assignees).method("PATCH").to(getIssuesApiRoute());
|
new Requester(root).with(ASSIGNEES, getLogins(assignees)).method("PATCH").to(getIssuesApiRoute());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove assignees.
|
||||||
|
*
|
||||||
|
* @param assignees
|
||||||
|
* the assignees
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void removeAssignees(GHUser... assignees) throws IOException {
|
public void removeAssignees(GHUser... assignees) throws IOException {
|
||||||
removeAssignees(Arrays.asList(assignees));
|
removeAssignees(Arrays.asList(assignees));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove assignees.
|
||||||
|
*
|
||||||
|
* @param assignees
|
||||||
|
* the assignees
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void removeAssignees(Collection<GHUser> assignees) throws IOException {
|
public void removeAssignees(Collection<GHUser> assignees) throws IOException {
|
||||||
root.retrieve().method("DELETE").withLogins(ASSIGNEES,assignees).inBody().to(getIssuesApiRoute()+"/assignees",this);
|
root.retrieve()
|
||||||
|
.method("DELETE")
|
||||||
|
.with(ASSIGNEES, getLogins(assignees))
|
||||||
|
.inBody()
|
||||||
|
.to(getIssuesApiRoute() + "/assignees", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets api route.
|
||||||
|
*
|
||||||
|
* @return the api route
|
||||||
|
*/
|
||||||
protected String getApiRoute() {
|
protected String getApiRoute() {
|
||||||
return getIssuesApiRoute();
|
return getIssuesApiRoute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets issues api route.
|
||||||
|
*
|
||||||
|
* @return the issues api route
|
||||||
|
*/
|
||||||
protected String getIssuesApiRoute() {
|
protected String getIssuesApiRoute() {
|
||||||
return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/issues/"+number;
|
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/issues/" + number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets assignee.
|
||||||
|
*
|
||||||
|
* @return the assignee
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHUser getAssignee() throws IOException {
|
public GHUser getAssignee() throws IOException {
|
||||||
return root.intern(assignee);
|
return root.intern(assignee);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets assignees.
|
||||||
|
*
|
||||||
|
* @return the assignees
|
||||||
|
*/
|
||||||
public List<GHUser> getAssignees() {
|
public List<GHUser> getAssignees() {
|
||||||
return Collections.unmodifiableList(Arrays.asList(assignees));
|
return Collections.unmodifiableList(Arrays.asList(assignees));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User who submitted the issue.
|
* User who submitted the issue.
|
||||||
|
*
|
||||||
|
* @return the user
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHUser getUser() throws IOException {
|
public GHUser getUser() throws IOException {
|
||||||
return root.intern(user);
|
return root.intern(user);
|
||||||
@@ -378,56 +597,115 @@ public class GHIssue extends GHObject implements Reactable{
|
|||||||
* Reports who has closed the issue.
|
* Reports who has closed the issue.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Note that GitHub doesn't always seem to report this information
|
* Note that GitHub doesn't always seem to report this information even for an issue that's already closed. See
|
||||||
* even for an issue that's already closed. See
|
|
||||||
* https://github.com/kohsuke/github-api/issues/60.
|
* https://github.com/kohsuke/github-api/issues/60.
|
||||||
|
*
|
||||||
|
* @return the closed by
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHUser getClosedBy() throws IOException {
|
public GHUser getClosedBy() throws IOException {
|
||||||
if(!"closed".equals(state)) return null;
|
if (!"closed".equals(state))
|
||||||
|
return null;
|
||||||
|
|
||||||
//TODO
|
// TODO
|
||||||
/*
|
/*
|
||||||
if (closed_by==null) {
|
* if (closed_by==null) { closed_by = owner.getIssue(number).getClosed_by(); }
|
||||||
closed_by = owner.getIssue(number).getClosed_by();
|
*/
|
||||||
}
|
|
||||||
*/
|
|
||||||
return root.intern(closed_by);
|
return root.intern(closed_by);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCommentsCount(){
|
/**
|
||||||
|
* Gets comments count.
|
||||||
|
*
|
||||||
|
* @return the comments count
|
||||||
|
*/
|
||||||
|
public int getCommentsCount() {
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns non-null if this issue is a shadow of a pull request.
|
* Returns non-null if this issue is a shadow of a pull request.
|
||||||
|
*
|
||||||
|
* @return the pull request
|
||||||
*/
|
*/
|
||||||
public PullRequest getPullRequest() {
|
public PullRequest getPullRequest() {
|
||||||
return pull_request;
|
return pull_request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is pull request boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isPullRequest() {
|
public boolean isPullRequest() {
|
||||||
return pull_request!=null;
|
return pull_request != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets milestone.
|
||||||
|
*
|
||||||
|
* @return the milestone
|
||||||
|
*/
|
||||||
public GHMilestone getMilestone() {
|
public GHMilestone getMilestone() {
|
||||||
return milestone;
|
return milestone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD"},
|
/**
|
||||||
justification = "JSON API")
|
* The type PullRequest.
|
||||||
public static class PullRequest{
|
*/
|
||||||
|
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD" },
|
||||||
|
justification = "JSON API")
|
||||||
|
public static class PullRequest {
|
||||||
private String diff_url, patch_url, html_url;
|
private String diff_url, patch_url, html_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets diff url.
|
||||||
|
*
|
||||||
|
* @return the diff url
|
||||||
|
*/
|
||||||
public URL getDiffUrl() {
|
public URL getDiffUrl() {
|
||||||
return GitHub.parseURL(diff_url);
|
return GitHub.parseURL(diff_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets patch url.
|
||||||
|
*
|
||||||
|
* @return the patch url
|
||||||
|
*/
|
||||||
public URL getPatchUrl() {
|
public URL getPatchUrl() {
|
||||||
return GitHub.parseURL(patch_url);
|
return GitHub.parseURL(patch_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public URL getUrl() {
|
public URL getUrl() {
|
||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static List<String> getLogins(Collection<GHUser> users) {
|
||||||
|
List<String> names = new ArrayList<String>(users.size());
|
||||||
|
for (GHUser a : users) {
|
||||||
|
names.add(a.getLogin());
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists events for this issue. See https://developer.github.com/v3/issues/events/
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHIssueEvent> listEvents() throws IOException {
|
||||||
|
return root.retrieve()
|
||||||
|
.asPagedIterable(owner.getApiTailUrl(String.format("/issues/%s/events", number)),
|
||||||
|
GHIssueEvent[].class,
|
||||||
|
item -> item.wrapUp(GHIssue.this));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The type GHIssueBuilder.
|
||||||
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public class GHIssueBuilder {
|
public class GHIssueBuilder {
|
||||||
@@ -16,45 +18,84 @@ public class GHIssueBuilder {
|
|||||||
GHIssueBuilder(GHRepository repo, String title) {
|
GHIssueBuilder(GHRepository repo, String title) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.builder = new Requester(repo.root);
|
this.builder = new Requester(repo.root);
|
||||||
builder.with("title",title);
|
builder.with("title", title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the main text of an issue, which is arbitrary multi-line text.
|
* Sets the main text of an issue, which is arbitrary multi-line text.
|
||||||
|
*
|
||||||
|
* @param str
|
||||||
|
* the str
|
||||||
|
* @return the gh issue builder
|
||||||
*/
|
*/
|
||||||
public GHIssueBuilder body(String str) {
|
public GHIssueBuilder body(String str) {
|
||||||
builder.with("body",str);
|
builder.with("body", str);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assignee gh issue builder.
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* the user
|
||||||
|
* @return the gh issue builder
|
||||||
|
*/
|
||||||
public GHIssueBuilder assignee(GHUser user) {
|
public GHIssueBuilder assignee(GHUser user) {
|
||||||
if (user!=null)
|
if (user != null)
|
||||||
assignees.add(user.getLogin());
|
assignees.add(user.getLogin());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assignee gh issue builder.
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* the user
|
||||||
|
* @return the gh issue builder
|
||||||
|
*/
|
||||||
public GHIssueBuilder assignee(String user) {
|
public GHIssueBuilder assignee(String user) {
|
||||||
if (user!=null)
|
if (user != null)
|
||||||
assignees.add(user);
|
assignees.add(user);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Milestone gh issue builder.
|
||||||
|
*
|
||||||
|
* @param milestone
|
||||||
|
* the milestone
|
||||||
|
* @return the gh issue builder
|
||||||
|
*/
|
||||||
public GHIssueBuilder milestone(GHMilestone milestone) {
|
public GHIssueBuilder milestone(GHMilestone milestone) {
|
||||||
if (milestone!=null)
|
if (milestone != null)
|
||||||
builder.with("milestone",milestone.getNumber());
|
builder.with("milestone", milestone.getNumber());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Label gh issue builder.
|
||||||
|
*
|
||||||
|
* @param label
|
||||||
|
* the label
|
||||||
|
* @return the gh issue builder
|
||||||
|
*/
|
||||||
public GHIssueBuilder label(String label) {
|
public GHIssueBuilder label(String label) {
|
||||||
if (label!=null)
|
if (label != null)
|
||||||
labels.add(label);
|
labels.add(label);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new issue.
|
* Creates a new issue.
|
||||||
|
*
|
||||||
|
* @return the gh issue
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHIssue create() throws IOException {
|
public GHIssue create() throws IOException {
|
||||||
return builder.with("labels",labels).with("assignees",assignees).to(repo.getApiTailUrl("issues"),GHIssue.class).wrap(repo);
|
return builder.with("labels", labels)
|
||||||
|
.with("assignees", assignees)
|
||||||
|
.to(repo.getApiTailUrl("issues"), GHIssue.class)
|
||||||
|
.wrap(repo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ import static org.kohsuke.github.Previews.*;
|
|||||||
* Comment to the issue
|
* Comment to the issue
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHIssue#comment(String)
|
* @see GHIssue#comment(String) GHIssue#comment(String)
|
||||||
* @see GHIssue#listComments()
|
* @see GHIssue#listComments() GHIssue#listComments()
|
||||||
*/
|
*/
|
||||||
public class GHIssueComment extends GHObject implements Reactable {
|
public class GHIssueComment extends GHObject implements Reactable {
|
||||||
GHIssue owner;
|
GHIssue owner;
|
||||||
@@ -41,13 +41,15 @@ public class GHIssueComment extends GHObject implements Reactable {
|
|||||||
private String body, gravatar_id, html_url, author_association;
|
private String body, gravatar_id, html_url, author_association;
|
||||||
private GHUser user; // not fully populated. beware.
|
private GHUser user; // not fully populated. beware.
|
||||||
|
|
||||||
/*package*/ GHIssueComment wrapUp(GHIssue owner) {
|
GHIssueComment wrapUp(GHIssue owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the issue to which this comment is associated.
|
* Gets the issue to which this comment is associated.
|
||||||
|
*
|
||||||
|
* @return the parent
|
||||||
*/
|
*/
|
||||||
public GHIssue getParent() {
|
public GHIssue getParent() {
|
||||||
return owner;
|
return owner;
|
||||||
@@ -55,6 +57,8 @@ public class GHIssueComment extends GHObject implements Reactable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The comment itself.
|
* The comment itself.
|
||||||
|
*
|
||||||
|
* @return the body
|
||||||
*/
|
*/
|
||||||
public String getBody() {
|
public String getBody() {
|
||||||
return body;
|
return body;
|
||||||
@@ -62,6 +66,8 @@ public class GHIssueComment extends GHObject implements Reactable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ID of the user who posted this comment.
|
* Gets the ID of the user who posted this comment.
|
||||||
|
*
|
||||||
|
* @return the user name
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public String getUserName() {
|
public String getUserName() {
|
||||||
@@ -70,22 +76,36 @@ public class GHIssueComment extends GHObject implements Reactable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the user who posted this comment.
|
* Gets the user who posted this comment.
|
||||||
|
*
|
||||||
|
* @return the user
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHUser getUser() throws IOException {
|
public GHUser getUser() throws IOException {
|
||||||
return owner == null || owner.root.isOffline() ? user : owner.root.getUser(user.getLogin());
|
return owner == null || owner.root.isOffline() ? user : owner.root.getUser(user.getLogin());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URL getHtmlUrl() {
|
public URL getHtmlUrl() {
|
||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets author association.
|
||||||
|
*
|
||||||
|
* @return the author association
|
||||||
|
*/
|
||||||
public GHCommentAuthorAssociation getAuthorAssociation() {
|
public GHCommentAuthorAssociation getAuthorAssociation() {
|
||||||
return GHCommentAuthorAssociation.valueOf(author_association);
|
return GHCommentAuthorAssociation.valueOf(author_association);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the body of the issue comment.
|
* Updates the body of the issue comment.
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void update(String body) throws IOException {
|
public void update(String body) throws IOException {
|
||||||
new Requester(owner.root).with("body", body).method("PATCH").to(getApiRoute(), GHIssueComment.class);
|
new Requester(owner.root).with("body", body).method("PATCH").to(getApiRoute(), GHIssueComment.class);
|
||||||
@@ -94,35 +114,33 @@ public class GHIssueComment extends GHObject implements Reactable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes this issue comment.
|
* Deletes this issue comment.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(owner.root).method("DELETE").to(getApiRoute());
|
new Requester(owner.root).method("DELETE").to(getApiRoute());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview @Deprecated
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public GHReaction createReaction(ReactionContent content) throws IOException {
|
public GHReaction createReaction(ReactionContent content) throws IOException {
|
||||||
return new Requester(owner.root)
|
return new Requester(owner.root).withPreview(SQUIRREL_GIRL)
|
||||||
.withPreview(SQUIRREL_GIRL)
|
|
||||||
.with("content", content.getContent())
|
.with("content", content.getContent())
|
||||||
.to(getApiRoute()+"/reactions", GHReaction.class).wrap(owner.root);
|
.to(getApiRoute() + "/reactions", GHReaction.class)
|
||||||
|
.wrap(owner.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview @Deprecated
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public PagedIterable<GHReaction> listReactions() {
|
public PagedIterable<GHReaction> listReactions() {
|
||||||
return new PagedIterable<GHReaction>() {
|
return owner.root.retrieve()
|
||||||
public PagedIterator<GHReaction> _iterator(int pageSize) {
|
.withPreview(SQUIRREL_GIRL)
|
||||||
return new PagedIterator<GHReaction>(owner.root.retrieve().withPreview(SQUIRREL_GIRL).asIterator(getApiRoute()+"/reactions", GHReaction[].class, pageSize)) {
|
.asPagedIterable(getApiRoute() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root));
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHReaction[] page) {
|
|
||||||
for (GHReaction c : page)
|
|
||||||
c.wrap(owner.root);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getApiRoute() {
|
private String getApiRoute() {
|
||||||
return "/repos/"+owner.getRepository().getOwnerName()+"/"+owner.getRepository().getName()+"/issues/comments/" + id;
|
return "/repos/" + owner.getRepository().getOwnerName() + "/" + owner.getRepository().getName()
|
||||||
|
+ "/issues/comments/" + id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
133
src/main/java/org/kohsuke/github/GHIssueEvent.java
Normal file
133
src/main/java/org/kohsuke/github/GHIssueEvent.java
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type GHIssueEvent.
|
||||||
|
*
|
||||||
|
* @author Martin van Zijl
|
||||||
|
*/
|
||||||
|
public class GHIssueEvent {
|
||||||
|
private GitHub root;
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
private String node_id;
|
||||||
|
private String url;
|
||||||
|
private GHUser actor;
|
||||||
|
private String event;
|
||||||
|
private String commit_id;
|
||||||
|
private String commit_url;
|
||||||
|
private String created_at;
|
||||||
|
|
||||||
|
private GHIssue issue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets id.
|
||||||
|
*
|
||||||
|
* @return the id
|
||||||
|
*/
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets node id.
|
||||||
|
*
|
||||||
|
* @return the node id
|
||||||
|
*/
|
||||||
|
public String getNodeId() {
|
||||||
|
return node_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets actor.
|
||||||
|
*
|
||||||
|
* @return the actor
|
||||||
|
*/
|
||||||
|
public GHUser getActor() {
|
||||||
|
return actor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets event.
|
||||||
|
*
|
||||||
|
* @return the event
|
||||||
|
*/
|
||||||
|
public String getEvent() {
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets commit id.
|
||||||
|
*
|
||||||
|
* @return the commit id
|
||||||
|
*/
|
||||||
|
public String getCommitId() {
|
||||||
|
return commit_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets commit url.
|
||||||
|
*
|
||||||
|
* @return the commit url
|
||||||
|
*/
|
||||||
|
public String getCommitUrl() {
|
||||||
|
return commit_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets created at.
|
||||||
|
*
|
||||||
|
* @return the created at
|
||||||
|
*/
|
||||||
|
public Date getCreatedAt() {
|
||||||
|
return GitHub.parseDate(created_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets root.
|
||||||
|
*
|
||||||
|
* @return the root
|
||||||
|
*/
|
||||||
|
public GitHub getRoot() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets issue.
|
||||||
|
*
|
||||||
|
* @return the issue
|
||||||
|
*/
|
||||||
|
public GHIssue getIssue() {
|
||||||
|
return issue;
|
||||||
|
}
|
||||||
|
|
||||||
|
GHIssueEvent wrapUp(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
GHIssueEvent wrapUp(GHIssue parent) {
|
||||||
|
this.issue = parent;
|
||||||
|
this.root = parent.root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("Issue %d was %s by %s on %s",
|
||||||
|
getIssue().getNumber(),
|
||||||
|
getEvent(),
|
||||||
|
getActor().getLogin(),
|
||||||
|
getCreatedAt().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,11 +4,11 @@ package org.kohsuke.github;
|
|||||||
* Search issues.
|
* Search issues.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GitHub#searchIssues()
|
* @see GitHub#searchIssues() GitHub#searchIssues()
|
||||||
*/
|
*/
|
||||||
public class GHIssueSearchBuilder extends GHSearchBuilder<GHIssue> {
|
public class GHIssueSearchBuilder extends GHSearchBuilder<GHIssue> {
|
||||||
/*package*/ GHIssueSearchBuilder(GitHub root) {
|
GHIssueSearchBuilder(GitHub root) {
|
||||||
super(root,IssueSearchResult.class);
|
super(root, IssueSearchResult.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,43 +19,91 @@ public class GHIssueSearchBuilder extends GHSearchBuilder<GHIssue> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mentions gh issue search builder.
|
||||||
|
*
|
||||||
|
* @param u
|
||||||
|
* the u
|
||||||
|
* @return the gh issue search builder
|
||||||
|
*/
|
||||||
public GHIssueSearchBuilder mentions(GHUser u) {
|
public GHIssueSearchBuilder mentions(GHUser u) {
|
||||||
return mentions(u.getLogin());
|
return mentions(u.getLogin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mentions gh issue search builder.
|
||||||
|
*
|
||||||
|
* @param login
|
||||||
|
* the login
|
||||||
|
* @return the gh issue search builder
|
||||||
|
*/
|
||||||
public GHIssueSearchBuilder mentions(String login) {
|
public GHIssueSearchBuilder mentions(String login) {
|
||||||
return q("mentions:"+login);
|
return q("mentions:" + login);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is open gh issue search builder.
|
||||||
|
*
|
||||||
|
* @return the gh issue search builder
|
||||||
|
*/
|
||||||
public GHIssueSearchBuilder isOpen() {
|
public GHIssueSearchBuilder isOpen() {
|
||||||
return q("is:open");
|
return q("is:open");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is closed gh issue search builder.
|
||||||
|
*
|
||||||
|
* @return the gh issue search builder
|
||||||
|
*/
|
||||||
public GHIssueSearchBuilder isClosed() {
|
public GHIssueSearchBuilder isClosed() {
|
||||||
return q("is:closed");
|
return q("is:closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is merged gh issue search builder.
|
||||||
|
*
|
||||||
|
* @return the gh issue search builder
|
||||||
|
*/
|
||||||
public GHIssueSearchBuilder isMerged() {
|
public GHIssueSearchBuilder isMerged() {
|
||||||
return q("is:merged");
|
return q("is:merged");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Order gh issue search builder.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh issue search builder
|
||||||
|
*/
|
||||||
public GHIssueSearchBuilder order(GHDirection v) {
|
public GHIssueSearchBuilder order(GHDirection v) {
|
||||||
req.with("order",v);
|
req.with("order", v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort gh issue search builder.
|
||||||
|
*
|
||||||
|
* @param sort
|
||||||
|
* the sort
|
||||||
|
* @return the gh issue search builder
|
||||||
|
*/
|
||||||
public GHIssueSearchBuilder sort(Sort sort) {
|
public GHIssueSearchBuilder sort(Sort sort) {
|
||||||
req.with("sort",sort);
|
req.with("sort", sort);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Sort { COMMENTS, CREATED, UPDATED }
|
/**
|
||||||
|
* The enum Sort.
|
||||||
|
*/
|
||||||
|
public enum Sort {
|
||||||
|
COMMENTS, CREATED, UPDATED
|
||||||
|
}
|
||||||
|
|
||||||
private static class IssueSearchResult extends SearchResult<GHIssue> {
|
private static class IssueSearchResult extends SearchResult<GHIssue> {
|
||||||
private GHIssue[] items;
|
private GHIssue[] items;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/*package*/ GHIssue[] getItems(GitHub root) {
|
GHIssue[] getItems(GitHub root) {
|
||||||
for (GHIssue i : items)
|
for (GHIssue i : items)
|
||||||
i.wrap(root);
|
i.wrap(root);
|
||||||
return items;
|
return items;
|
||||||
|
|||||||
@@ -25,10 +25,10 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see GHPullRequestQueryBuilder#state(GHIssueState)
|
* The enum GHIssueState.
|
||||||
|
*
|
||||||
|
* @see GHPullRequestQueryBuilder#state(GHIssueState) GHPullRequestQueryBuilder#state(GHIssueState)
|
||||||
*/
|
*/
|
||||||
public enum GHIssueState {
|
public enum GHIssueState {
|
||||||
OPEN,
|
OPEN, CLOSED, ALL
|
||||||
CLOSED,
|
|
||||||
ALL
|
|
||||||
}
|
}
|
||||||
@@ -10,45 +10,72 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
|
|||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", justification = "JSON API")
|
@SuppressFBWarnings(value = "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", justification = "JSON API")
|
||||||
public class GHKey {
|
public class GHKey {
|
||||||
/*package almost final*/ GitHub root;
|
/* package almost final */ GitHub root;
|
||||||
|
|
||||||
protected String url, key, title;
|
protected String url, key, title;
|
||||||
protected boolean verified;
|
protected boolean verified;
|
||||||
protected int id;
|
protected int id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets id.
|
||||||
|
*
|
||||||
|
* @return the id
|
||||||
|
*/
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets key.
|
||||||
|
*
|
||||||
|
* @return the key
|
||||||
|
*/
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets title.
|
||||||
|
*
|
||||||
|
* @return the title
|
||||||
|
*/
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Something like "https://api.github.com/user/keys/73593"
|
* Something like "https://api.github.com/user/keys/73593"
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
*/
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets root.
|
||||||
|
*
|
||||||
|
* @return the root
|
||||||
|
*/
|
||||||
public GitHub getRoot() {
|
public GitHub getRoot() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is verified boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isVerified() {
|
public boolean isVerified() {
|
||||||
return verified;
|
return verified;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHKey wrap(GitHub root) {
|
GHKey wrap(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this).append("title",title).append("id",id).append("key",key).toString();
|
return new ToStringBuilder(this).append("title", title).append("id", id).append("key", key).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,53 +4,133 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static org.kohsuke.github.Previews.SYMMETRA;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The type GHLabel.
|
||||||
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHIssue#getLabels()
|
* @see GHIssue#getLabels() GHIssue#getLabels()
|
||||||
* @see GHRepository#listLabels()
|
* @see GHRepository#listLabels() GHRepository#listLabels()
|
||||||
*/
|
*/
|
||||||
public class GHLabel {
|
public class GHLabel {
|
||||||
private String url, name, color;
|
private String url, name, color, description;
|
||||||
private GHRepository repo;
|
private GHRepository repo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets name.
|
||||||
|
*
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Color code without leading '#', such as 'f29513'
|
* Color code without leading '#', such as 'f29513'
|
||||||
|
*
|
||||||
|
* @return the color
|
||||||
*/
|
*/
|
||||||
public String getColor() {
|
public String getColor() {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHLabel wrapUp(GHRepository repo) {
|
/**
|
||||||
|
* Purpose of Label
|
||||||
|
*
|
||||||
|
* @return the description
|
||||||
|
*/
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
GHLabel wrapUp(GHRepository repo) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
repo.root.retrieve().method("DELETE").to(url);
|
repo.root.retrieve().method("DELETE").to(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Sets color.
|
||||||
|
*
|
||||||
* @param newColor
|
* @param newColor
|
||||||
* 6-letter hex color code, like "f29513"
|
* 6-letter hex color code, like "f29513"
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void setColor(String newColor) throws IOException {
|
public void setColor(String newColor) throws IOException {
|
||||||
repo.root.retrieve().method("PATCH").with("name", name).with("color", newColor).to(url);
|
repo.root.retrieve()
|
||||||
|
.method("PATCH")
|
||||||
|
.withPreview(SYMMETRA)
|
||||||
|
.with("name", name)
|
||||||
|
.with("color", newColor)
|
||||||
|
.with("description", description)
|
||||||
|
.to(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ static Collection<String> toNames(Collection<GHLabel> labels) {
|
/**
|
||||||
|
* Sets description.
|
||||||
|
*
|
||||||
|
* @param newDescription
|
||||||
|
* Description of label
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
@Preview
|
||||||
|
@Deprecated
|
||||||
|
public void setDescription(String newDescription) throws IOException {
|
||||||
|
repo.root.retrieve()
|
||||||
|
.method("PATCH")
|
||||||
|
.withPreview(SYMMETRA)
|
||||||
|
.with("name", name)
|
||||||
|
.with("color", color)
|
||||||
|
.with("description", newDescription)
|
||||||
|
.to(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Collection<String> toNames(Collection<GHLabel> labels) {
|
||||||
List<String> r = new ArrayList<String>();
|
List<String> r = new ArrayList<String>();
|
||||||
for (GHLabel l : labels) {
|
for (GHLabel l : labels) {
|
||||||
r.add(l.getName());
|
r.add(l.getName());
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object o) {
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
if (o == null || getClass() != o.getClass())
|
||||||
|
return false;
|
||||||
|
final GHLabel ghLabel = (GHLabel) o;
|
||||||
|
return Objects.equals(url, ghLabel.url) && Objects.equals(name, ghLabel.name)
|
||||||
|
&& Objects.equals(color, ghLabel.color) && Objects.equals(repo, ghLabel.repo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(url, name, color, repo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,25 +32,21 @@ import java.net.URL;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.kohsuke.github.Previews.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The GitHub Preview API's license information
|
* The GitHub Preview API's license information
|
||||||
* <p>
|
|
||||||
* WARNING: This uses a PREVIEW API - subject to change.
|
|
||||||
*
|
*
|
||||||
* @author Duncan Dickinson
|
* @author Duncan Dickinson
|
||||||
* @see GitHub#getLicense(String)
|
* @see GitHub#getLicense(String) GitHub#getLicense(String)
|
||||||
* @see GHRepository#getLicense()
|
* @see GHRepository#getLicense() GHRepository#getLicense()
|
||||||
* @see <a href="https://developer.github.com/v3/licenses/">https://developer.github.com/v3/licenses/</a>
|
* @see <a href="https://developer.github.com/v3/licenses/">https://developer.github.com/v3/licenses/</a>
|
||||||
*/
|
*/
|
||||||
@Preview @Deprecated
|
@SuppressWarnings({ "UnusedDeclaration" })
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
|
justification = "JSON API")
|
||||||
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
|
|
||||||
public class GHLicense extends GHObject {
|
public class GHLicense extends GHObject {
|
||||||
@SuppressFBWarnings("IS2_INCONSISTENT_SYNC") // root is set before the object is returned to the app
|
@SuppressFBWarnings("IS2_INCONSISTENT_SYNC")
|
||||||
/*package almost final*/ GitHub root;
|
// root is set before the object is returned to the app
|
||||||
|
/* package almost final */ GitHub root;
|
||||||
|
|
||||||
// these fields are always present, even in the short form
|
// these fields are always present, even in the short form
|
||||||
protected String key, name;
|
protected String key, name;
|
||||||
@@ -65,6 +61,8 @@ public class GHLicense extends GHObject {
|
|||||||
protected List<String> forbidden = new ArrayList<String>();
|
protected List<String> forbidden = new ArrayList<String>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets key.
|
||||||
|
*
|
||||||
* @return a mnemonic for the license
|
* @return a mnemonic for the license
|
||||||
*/
|
*/
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
@@ -72,6 +70,8 @@ public class GHLicense extends GHObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets name.
|
||||||
|
*
|
||||||
* @return the license name
|
* @return the license name
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -90,6 +90,8 @@ public class GHLicense extends GHObject {
|
|||||||
* Featured licenses are bold in the new repository drop-down
|
* Featured licenses are bold in the new repository drop-down
|
||||||
*
|
*
|
||||||
* @return True if the license is featured, false otherwise
|
* @return True if the license is featured, false otherwise
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public Boolean isFeatured() throws IOException {
|
public Boolean isFeatured() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
@@ -101,36 +103,85 @@ public class GHLicense extends GHObject {
|
|||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets description.
|
||||||
|
*
|
||||||
|
* @return the description
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public String getDescription() throws IOException {
|
public String getDescription() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets category.
|
||||||
|
*
|
||||||
|
* @return the category
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public String getCategory() throws IOException {
|
public String getCategory() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return category;
|
return category;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets implementation.
|
||||||
|
*
|
||||||
|
* @return the implementation
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public String getImplementation() throws IOException {
|
public String getImplementation() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return implementation;
|
return implementation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets required.
|
||||||
|
*
|
||||||
|
* @return the required
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public List<String> getRequired() throws IOException {
|
public List<String> getRequired() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return required;
|
return required;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets permitted.
|
||||||
|
*
|
||||||
|
* @return the permitted
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public List<String> getPermitted() throws IOException {
|
public List<String> getPermitted() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return permitted;
|
return permitted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets forbidden.
|
||||||
|
*
|
||||||
|
* @return the forbidden
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public List<String> getForbidden() throws IOException {
|
public List<String> getForbidden() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return forbidden;
|
return forbidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets body.
|
||||||
|
*
|
||||||
|
* @return the body
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public String getBody() throws IOException {
|
public String getBody() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return body;
|
return body;
|
||||||
@@ -138,19 +189,25 @@ public class GHLicense extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fully populate the data by retrieving missing data.
|
* Fully populate the data by retrieving missing data.
|
||||||
*
|
* <p>
|
||||||
* Depending on the original API call where this object is created, it may not contain everything.
|
* Depending on the original API call where this object is created, it may not contain everything.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
protected synchronized void populate() throws IOException {
|
protected synchronized void populate() throws IOException {
|
||||||
if (description!=null) return; // already populated
|
if (description != null)
|
||||||
|
return; // already populated
|
||||||
|
|
||||||
root.retrieve().withPreview(DRAX).to(url, this);
|
root.retrieve().to(url, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o)
|
||||||
if (!(o instanceof GHLicense)) return false;
|
return true;
|
||||||
|
if (!(o instanceof GHLicense))
|
||||||
|
return false;
|
||||||
|
|
||||||
GHLicense that = (GHLicense) o;
|
GHLicense that = (GHLicense) o;
|
||||||
return this.url.equals(that.url);
|
return this.url.equals(that.url);
|
||||||
@@ -161,7 +218,7 @@ public class GHLicense extends GHObject {
|
|||||||
return url.hashCode();
|
return url.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHLicense wrap(GitHub root) {
|
GHLicense wrap(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.util.Locale;
|
|||||||
* Represents a membership of a user in an organization.
|
* Represents a membership of a user in an organization.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHMyself#listOrgMemberships()
|
* @see GHMyself#listOrgMemberships() GHMyself#listOrgMemberships()
|
||||||
*/
|
*/
|
||||||
public class GHMembership /* extends GHObject --- but it doesn't have id, created_at, etc. */ {
|
public class GHMembership /* extends GHObject --- but it doesn't have id, created_at, etc. */ {
|
||||||
GitHub root;
|
GitHub root;
|
||||||
@@ -19,22 +19,47 @@ public class GHMembership /* extends GHObject --- but it doesn't have id, create
|
|||||||
GHUser user;
|
GHUser user;
|
||||||
GHOrganization organization;
|
GHOrganization organization;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public URL getUrl() {
|
public URL getUrl() {
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets state.
|
||||||
|
*
|
||||||
|
* @return the state
|
||||||
|
*/
|
||||||
public State getState() {
|
public State getState() {
|
||||||
return Enum.valueOf(State.class, state.toUpperCase(Locale.ENGLISH));
|
return Enum.valueOf(State.class, state.toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets role.
|
||||||
|
*
|
||||||
|
* @return the role
|
||||||
|
*/
|
||||||
public Role getRole() {
|
public Role getRole() {
|
||||||
return Enum.valueOf(Role.class, role.toUpperCase(Locale.ENGLISH));
|
return Enum.valueOf(Role.class, role.toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets user.
|
||||||
|
*
|
||||||
|
* @return the user
|
||||||
|
*/
|
||||||
public GHUser getUser() {
|
public GHUser getUser() {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets organization.
|
||||||
|
*
|
||||||
|
* @return the organization
|
||||||
|
*/
|
||||||
public GHOrganization getOrganization() {
|
public GHOrganization getOrganization() {
|
||||||
return organization;
|
return organization;
|
||||||
}
|
}
|
||||||
@@ -42,20 +67,24 @@ public class GHMembership /* extends GHObject --- but it doesn't have id, create
|
|||||||
/**
|
/**
|
||||||
* Accepts a pending invitation to an organization.
|
* Accepts a pending invitation to an organization.
|
||||||
*
|
*
|
||||||
* @see GHMyself#getMembership(GHOrganization)
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @see GHMyself#getMembership(GHOrganization) GHMyself#getMembership(GHOrganization)
|
||||||
*/
|
*/
|
||||||
public void activate() throws IOException {
|
public void activate() throws IOException {
|
||||||
root.retrieve().method("PATCH").with("state",State.ACTIVE).to(url,this);
|
root.retrieve().method("PATCH").with("state", State.ACTIVE).to(url, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHMembership wrap(GitHub root) {
|
GHMembership wrap(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
if (user!=null) user = root.getUser(user.wrapUp(root));
|
if (user != null)
|
||||||
if (organization!=null) organization.wrapUp(root);
|
user = root.getUser(user.wrapUp(root));
|
||||||
|
if (organization != null)
|
||||||
|
organization.wrapUp(root);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ static void wrap(GHMembership[] page, GitHub root) {
|
static void wrap(GHMembership[] page, GitHub root) {
|
||||||
for (GHMembership m : page)
|
for (GHMembership m : page)
|
||||||
m.wrap(root);
|
m.wrap(root);
|
||||||
}
|
}
|
||||||
@@ -78,7 +107,6 @@ public class GHMembership /* extends GHObject --- but it doesn't have id, create
|
|||||||
* Whether a role is currently active or waiting for acceptance (pending)
|
* Whether a role is currently active or waiting for acceptance (pending)
|
||||||
*/
|
*/
|
||||||
public enum State {
|
public enum State {
|
||||||
ACTIVE,
|
ACTIVE, PENDING;
|
||||||
PENDING;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
89
src/main/java/org/kohsuke/github/GHMeta.java
Normal file
89
src/main/java/org/kohsuke/github/GHMeta.java
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that wraps the list of GitHub's IP addresses.
|
||||||
|
*
|
||||||
|
* @author Paulo Miguel Almeida
|
||||||
|
* @see GitHub#getMeta() GitHub#getMeta()
|
||||||
|
* @see <a href="https://developer.github.com/v3/meta/#meta">Get Meta</a>
|
||||||
|
*/
|
||||||
|
public class GHMeta {
|
||||||
|
|
||||||
|
@JsonProperty("verifiable_password_authentication")
|
||||||
|
private boolean verifiablePasswordAuthentication;
|
||||||
|
private List<String> hooks;
|
||||||
|
private List<String> git;
|
||||||
|
private List<String> web;
|
||||||
|
private List<String> api;
|
||||||
|
private List<String> pages;
|
||||||
|
private List<String> importer = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is verifiable password authentication boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
|
public boolean isVerifiablePasswordAuthentication() {
|
||||||
|
return verifiablePasswordAuthentication;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets hooks.
|
||||||
|
*
|
||||||
|
* @return the hooks
|
||||||
|
*/
|
||||||
|
public List<String> getHooks() {
|
||||||
|
return Collections.unmodifiableList(hooks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets git.
|
||||||
|
*
|
||||||
|
* @return the git
|
||||||
|
*/
|
||||||
|
public List<String> getGit() {
|
||||||
|
return Collections.unmodifiableList(git);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets web.
|
||||||
|
*
|
||||||
|
* @return the web
|
||||||
|
*/
|
||||||
|
public List<String> getWeb() {
|
||||||
|
return Collections.unmodifiableList(web);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets api.
|
||||||
|
*
|
||||||
|
* @return the api
|
||||||
|
*/
|
||||||
|
public List<String> getApi() {
|
||||||
|
return Collections.unmodifiableList(api);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets pages.
|
||||||
|
*
|
||||||
|
* @return the pages
|
||||||
|
*/
|
||||||
|
public List<String> getPages() {
|
||||||
|
return Collections.unmodifiableList(pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets importer.
|
||||||
|
*
|
||||||
|
* @return the importer
|
||||||
|
*/
|
||||||
|
public List<String> getImporter() {
|
||||||
|
return Collections.unmodifiableList(importer);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,9 +6,9 @@ import java.util.Date;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* The type GHMilestone.
|
||||||
* @author Yusuke Kokubo
|
|
||||||
*
|
*
|
||||||
|
* @author Yusuke Kokubo
|
||||||
*/
|
*/
|
||||||
public class GHMilestone extends GHObject {
|
public class GHMilestone extends GHObject {
|
||||||
GitHub root;
|
GitHub root;
|
||||||
@@ -19,46 +19,98 @@ public class GHMilestone extends GHObject {
|
|||||||
private int closed_issues, open_issues, number;
|
private int closed_issues, open_issues, number;
|
||||||
protected String closed_at;
|
protected String closed_at;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets root.
|
||||||
|
*
|
||||||
|
* @return the root
|
||||||
|
*/
|
||||||
public GitHub getRoot() {
|
public GitHub getRoot() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets owner.
|
||||||
|
*
|
||||||
|
* @return the owner
|
||||||
|
*/
|
||||||
public GHRepository getOwner() {
|
public GHRepository getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets creator.
|
||||||
|
*
|
||||||
|
* @return the creator
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHUser getCreator() throws IOException {
|
public GHUser getCreator() throws IOException {
|
||||||
return root.intern(creator);
|
return root.intern(creator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets due on.
|
||||||
|
*
|
||||||
|
* @return the due on
|
||||||
|
*/
|
||||||
public Date getDueOn() {
|
public Date getDueOn() {
|
||||||
if (due_on == null) return null;
|
if (due_on == null)
|
||||||
|
return null;
|
||||||
return GitHub.parseDate(due_on);
|
return GitHub.parseDate(due_on);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When was this milestone closed?
|
* When was this milestone closed?
|
||||||
|
*
|
||||||
|
* @return the closed at
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public Date getClosedAt() throws IOException {
|
public Date getClosedAt() throws IOException {
|
||||||
return GitHub.parseDate(closed_at);
|
return GitHub.parseDate(closed_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets title.
|
||||||
|
*
|
||||||
|
* @return the title
|
||||||
|
*/
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets description.
|
||||||
|
*
|
||||||
|
* @return the description
|
||||||
|
*/
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets closed issues.
|
||||||
|
*
|
||||||
|
* @return the closed issues
|
||||||
|
*/
|
||||||
public int getClosedIssues() {
|
public int getClosedIssues() {
|
||||||
return closed_issues;
|
return closed_issues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets open issues.
|
||||||
|
*
|
||||||
|
* @return the open issues
|
||||||
|
*/
|
||||||
public int getOpenIssues() {
|
public int getOpenIssues() {
|
||||||
return open_issues;
|
return open_issues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets number.
|
||||||
|
*
|
||||||
|
* @return the number
|
||||||
|
*/
|
||||||
public int getNumber() {
|
public int getNumber() {
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
@@ -66,13 +118,21 @@ public class GHMilestone extends GHObject {
|
|||||||
public URL getHtmlUrl() {
|
public URL getHtmlUrl() {
|
||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets state.
|
||||||
|
*
|
||||||
|
* @return the state
|
||||||
|
*/
|
||||||
public GHMilestoneState getState() {
|
public GHMilestoneState getState() {
|
||||||
return Enum.valueOf(GHMilestoneState.class, state.toUpperCase(Locale.ENGLISH));
|
return Enum.valueOf(GHMilestoneState.class, state.toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes this milestone.
|
* Closes this milestone.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
edit("state", "closed");
|
edit("state", "closed");
|
||||||
@@ -80,19 +140,80 @@ public class GHMilestone extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Reopens this milestone.
|
* Reopens this milestone.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void reopen() throws IOException {
|
public void reopen() throws IOException {
|
||||||
edit("state", "open");
|
edit("state", "open");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes this milestone.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void delete() throws IOException {
|
||||||
|
root.retrieve().method("DELETE").to(getApiRoute());
|
||||||
|
}
|
||||||
|
|
||||||
private void edit(String key, Object value) throws IOException {
|
private void edit(String key, Object value) throws IOException {
|
||||||
new Requester(root)._with(key, value).method("PATCH").to(getApiRoute());
|
new Requester(root).with(key, value).method("PATCH").to(getApiRoute());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets title.
|
||||||
|
*
|
||||||
|
* @param title
|
||||||
|
* the title
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void setTitle(String title) throws IOException {
|
||||||
|
edit("title", title);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets description.
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
* the description
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void setDescription(String description) throws IOException {
|
||||||
|
edit("description", description);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets due on.
|
||||||
|
*
|
||||||
|
* @param dueOn
|
||||||
|
* the due on
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void setDueOn(Date dueOn) throws IOException {
|
||||||
|
edit("due_on", GitHub.printDate(dueOn));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets api route.
|
||||||
|
*
|
||||||
|
* @return the api route
|
||||||
|
*/
|
||||||
protected String getApiRoute() {
|
protected String getApiRoute() {
|
||||||
return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/milestones/"+number;
|
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/milestones/" + number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap gh milestone.
|
||||||
|
*
|
||||||
|
* @param repo
|
||||||
|
* the repo
|
||||||
|
* @return the gh milestone
|
||||||
|
*/
|
||||||
public GHMilestone wrap(GHRepository repo) {
|
public GHMilestone wrap(GHRepository repo) {
|
||||||
this.owner = repo;
|
this.owner = repo;
|
||||||
this.root = repo.root;
|
this.root = repo.root;
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* The enum GHMilestoneState.
|
||||||
* @author Yusuke Kokubo
|
|
||||||
*
|
*
|
||||||
|
* @author Yusuke Kokubo
|
||||||
*/
|
*/
|
||||||
public enum GHMilestoneState {
|
public enum GHMilestoneState {
|
||||||
OPEN,
|
OPEN, CLOSED
|
||||||
CLOSED
|
|
||||||
}
|
}
|
||||||
@@ -44,8 +44,12 @@ public class GHMyself extends GHUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* Gets emails.
|
||||||
* Use {@link #getEmails2()}
|
*
|
||||||
|
* @return the emails
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @deprecated Use {@link #getEmails2()}
|
||||||
*/
|
*/
|
||||||
public List<String> getEmails() throws IOException {
|
public List<String> getEmails() throws IOException {
|
||||||
List<GHEmail> src = getEmails2();
|
List<GHEmail> src = getEmails2();
|
||||||
@@ -58,13 +62,13 @@ public class GHMyself extends GHUser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the read-only list of e-mail addresses configured for you.
|
* Returns the read-only list of e-mail addresses configured for you.
|
||||||
|
* <p>
|
||||||
|
* This corresponds to the stuff you configure in https://github.com/settings/emails, and not to be confused with
|
||||||
|
* {@link #getEmail()} that shows your public e-mail address set in https://github.com/settings/profile
|
||||||
*
|
*
|
||||||
* This corresponds to the stuff you configure in https://github.com/settings/emails,
|
* @return Always non-null.
|
||||||
* and not to be confused with {@link #getEmail()} that shows your public e-mail address
|
* @throws IOException
|
||||||
* set in https://github.com/settings/profile
|
* the io exception
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* Always non-null.
|
|
||||||
*/
|
*/
|
||||||
public List<GHEmail> getEmails2() throws IOException {
|
public List<GHEmail> getEmails2() throws IOException {
|
||||||
GHEmail[] addresses = root.retrieve().to("/user/emails", GHEmail[].class);
|
GHEmail[] addresses = root.retrieve().to("/user/emails", GHEmail[].class);
|
||||||
@@ -73,12 +77,13 @@ public class GHMyself extends GHUser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the read-only list of all the pulic keys of the current user.
|
* Returns the read-only list of all the pulic keys of the current user.
|
||||||
|
* <p>
|
||||||
|
* NOTE: When using OAuth authenticaiton, the READ/WRITE User scope is required by the GitHub APIs, otherwise you
|
||||||
|
* will get a 404 NOT FOUND.
|
||||||
*
|
*
|
||||||
* NOTE: When using OAuth authenticaiton, the READ/WRITE User scope is
|
* @return Always non-null.
|
||||||
* required by the GitHub APIs, otherwise you will get a 404 NOT FOUND.
|
* @throws IOException
|
||||||
*
|
* the io exception
|
||||||
* @return
|
|
||||||
* Always non-null.
|
|
||||||
*/
|
*/
|
||||||
public List<GHKey> getPublicKeys() throws IOException {
|
public List<GHKey> getPublicKeys() throws IOException {
|
||||||
return Collections.unmodifiableList(Arrays.asList(root.retrieve().to("/user/keys", GHKey[].class)));
|
return Collections.unmodifiableList(Arrays.asList(root.retrieve().to("/user/keys", GHKey[].class)));
|
||||||
@@ -86,27 +91,31 @@ public class GHMyself extends GHUser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the read-only list of all the public verified keys of the current user.
|
* Returns the read-only list of all the public verified keys of the current user.
|
||||||
|
* <p>
|
||||||
|
* Differently from the getPublicKeys() method, the retrieval of the user's verified public keys does not require
|
||||||
|
* any READ/WRITE OAuth Scope to the user's profile.
|
||||||
*
|
*
|
||||||
* Differently from the getPublicKeys() method, the retrieval of the user's
|
* @return Always non-null.
|
||||||
* verified public keys does not require any READ/WRITE OAuth Scope to the
|
* @throws IOException
|
||||||
* user's profile.
|
* the io exception
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* Always non-null.
|
|
||||||
*/
|
*/
|
||||||
public List<GHVerifiedKey> getPublicVerifiedKeys() throws IOException {
|
public List<GHVerifiedKey> getPublicVerifiedKeys() throws IOException {
|
||||||
return Collections.unmodifiableList(Arrays.asList(root.retrieve().to(
|
return Collections.unmodifiableList(
|
||||||
"/users/" + getLogin() + "/keys", GHVerifiedKey[].class)));
|
Arrays.asList(root.retrieve().to("/users/" + getLogin() + "/keys", GHVerifiedKey[].class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the organization that this user belongs to.
|
* Gets the organization that this user belongs to.
|
||||||
|
*
|
||||||
|
* @return the all organizations
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHPersonSet<GHOrganization> getAllOrganizations() throws IOException {
|
public GHPersonSet<GHOrganization> getAllOrganizations() throws IOException {
|
||||||
GHPersonSet<GHOrganization> orgs = new GHPersonSet<GHOrganization>();
|
GHPersonSet<GHOrganization> orgs = new GHPersonSet<GHOrganization>();
|
||||||
Set<String> names = new HashSet<String>();
|
Set<String> names = new HashSet<String>();
|
||||||
for (GHOrganization o : root.retrieve().to("/user/orgs", GHOrganization[].class)) {
|
for (GHOrganization o : root.retrieve().to("/user/orgs", GHOrganization[].class)) {
|
||||||
if (names.add(o.getLogin())) // in case of rumoured duplicates in the data
|
if (names.add(o.getLogin())) // in case of rumoured duplicates in the data
|
||||||
orgs.add(root.getOrganization(o.getLogin()));
|
orgs.add(root.getOrganization(o.getLogin()));
|
||||||
}
|
}
|
||||||
return orgs;
|
return orgs;
|
||||||
@@ -114,11 +123,15 @@ public class GHMyself extends GHUser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the all repositories this user owns (public and private).
|
* Gets the all repositories this user owns (public and private).
|
||||||
|
*
|
||||||
|
* @return the all repositories
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public synchronized Map<String,GHRepository> getAllRepositories() throws IOException {
|
public synchronized Map<String, GHRepository> getAllRepositories() throws IOException {
|
||||||
Map<String,GHRepository> repositories = new TreeMap<String, GHRepository>();
|
Map<String, GHRepository> repositories = new TreeMap<String, GHRepository>();
|
||||||
for (GHRepository r : listAllRepositories()) {
|
for (GHRepository r : listAllRepositories()) {
|
||||||
repositories.put(r.getName(),r);
|
repositories.put(r.getName(), r);
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableMap(repositories);
|
return Collections.unmodifiableMap(repositories);
|
||||||
}
|
}
|
||||||
@@ -126,52 +139,53 @@ public class GHMyself extends GHUser {
|
|||||||
/**
|
/**
|
||||||
* Lists up all repositories this user owns (public and private).
|
* Lists up all repositories this user owns (public and private).
|
||||||
*
|
*
|
||||||
* Unlike {@link #getAllRepositories()}, this does not wait until all the repositories are returned.
|
* Unlike {@link #getAllRepositories()}, this does not wait until all the repositories are returned. Repositories
|
||||||
* Repositories are returned by GitHub API with a 30 items per page.
|
* are returned by GitHub API with a 30 items per page.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PagedIterable<GHRepository> listRepositories() {
|
public PagedIterable<GHRepository> listRepositories() {
|
||||||
return listRepositories(30);
|
return listRepositories(30);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List repositories that are accessible to the authenticated user (public and private) using the specified page size.
|
* List repositories that are accessible to the authenticated user (public and private) using the specified page
|
||||||
|
* size.
|
||||||
*
|
*
|
||||||
* This includes repositories owned by the authenticated user, repositories that belong to other users
|
* This includes repositories owned by the authenticated user, repositories that belong to other users where the
|
||||||
* where the authenticated user is a collaborator, and other organizations' repositories that the authenticated
|
* authenticated user is a collaborator, and other organizations' repositories that the authenticated user has
|
||||||
* user has access to through an organization membership.
|
* access to through an organization membership.
|
||||||
*
|
*
|
||||||
* @param pageSize size for each page of items returned by GitHub. Maximum page size is 100.
|
* @param pageSize
|
||||||
|
* size for each page of items returned by GitHub. Maximum page size is 100.
|
||||||
*
|
*
|
||||||
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
|
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
||||||
return listRepositories(pageSize, RepositoryListFilter.ALL);
|
return listRepositories(pageSize, RepositoryListFilter.ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List repositories of a certain type that are accessible by current authenticated user using the specified page size.
|
* List repositories of a certain type that are accessible by current authenticated user using the specified page
|
||||||
|
* size.
|
||||||
*
|
*
|
||||||
* @param pageSize size for each page of items returned by GitHub. Maximum page size is 100.
|
* @param pageSize
|
||||||
* @param repoType type of repository returned in the listing
|
* size for each page of items returned by GitHub. Maximum page size is 100.
|
||||||
|
* @param repoType
|
||||||
|
* type of repository returned in the listing
|
||||||
|
* @return the paged iterable
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHRepository> listRepositories(final int pageSize, final RepositoryListFilter repoType) {
|
public PagedIterable<GHRepository> listRepositories(final int pageSize, final RepositoryListFilter repoType) {
|
||||||
return new PagedIterable<GHRepository>() {
|
return root.retrieve()
|
||||||
public PagedIterator<GHRepository> _iterator(int pageSize) {
|
.with("type", repoType)
|
||||||
return new PagedIterator<GHRepository>(root.retrieve().with("type",repoType).asIterator("/user/repos", GHRepository[].class, pageSize)) {
|
.asPagedIterable("/user/repos", GHRepository[].class, item -> item.wrap(root))
|
||||||
@Override
|
.withPageSize(pageSize);
|
||||||
protected void wrapUp(GHRepository[] page) {
|
|
||||||
for (GHRepository c : page)
|
|
||||||
c.wrap(root);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}.withPageSize(pageSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* List all repositories paged iterable.
|
||||||
* Use {@link #listRepositories()}
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
* @deprecated Use {@link #listRepositories()}
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHRepository> listAllRepositories() {
|
public PagedIterable<GHRepository> listAllRepositories() {
|
||||||
return listRepositories();
|
return listRepositories();
|
||||||
@@ -179,6 +193,8 @@ public class GHMyself extends GHUser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* List your organization memberships
|
* List your organization memberships
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHMembership> listOrgMemberships() {
|
public PagedIterable<GHMembership> listOrgMemberships() {
|
||||||
return listOrgMemberships(null);
|
return listOrgMemberships(null);
|
||||||
@@ -188,30 +204,30 @@ public class GHMyself extends GHUser {
|
|||||||
* List your organization memberships
|
* List your organization memberships
|
||||||
*
|
*
|
||||||
* @param state
|
* @param state
|
||||||
* Filter by a specific state
|
* Filter by a specific state
|
||||||
|
* @return the paged iterable
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHMembership> listOrgMemberships(final GHMembership.State state) {
|
public PagedIterable<GHMembership> listOrgMemberships(final GHMembership.State state) {
|
||||||
return new PagedIterable<GHMembership>() {
|
return root.retrieve()
|
||||||
public PagedIterator<GHMembership> _iterator(int pageSize) {
|
.with("state", state)
|
||||||
return new PagedIterator<GHMembership>(root.retrieve().with("state",state).asIterator("/user/memberships/orgs", GHMembership[].class, pageSize)) {
|
.asPagedIterable("/user/memberships/orgs", GHMembership[].class, item -> item.wrap(root));
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHMembership[] page) {
|
|
||||||
GHMembership.wrap(page,root);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets your membership in a specific organization.
|
* Gets your membership in a specific organization.
|
||||||
|
*
|
||||||
|
* @param o
|
||||||
|
* the o
|
||||||
|
* @return the membership
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHMembership getMembership(GHOrganization o) throws IOException {
|
public GHMembership getMembership(GHOrganization o) throws IOException {
|
||||||
return root.retrieve().to("/user/memberships/orgs/"+o.getLogin(),GHMembership.class).wrap(root);
|
return root.retrieve().to("/user/memberships/orgs/" + o.getLogin(), GHMembership.class).wrap(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void addEmails(Collection<String> emails) throws IOException {
|
// public void addEmails(Collection<String> emails) throws IOException {
|
||||||
//// new Requester(root,ApiVersion.V3).withCredential().to("/user/emails");
|
//// new Requester(root,ApiVersion.V3).withCredential().to("/user/emails");
|
||||||
// root.retrieveWithAuth3()
|
// root.retrieveWithAuth3()
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,23 +9,19 @@ import java.util.NoSuchElementException;
|
|||||||
* Listens to GitHub notification stream.
|
* Listens to GitHub notification stream.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* This class supports two modes of retrieving notifications that can
|
* This class supports two modes of retrieving notifications that can be controlled via {@link #nonBlocking(boolean)}.
|
||||||
* be controlled via {@link #nonBlocking(boolean)}.
|
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* In the blocking mode, which is the default, iterator will be infinite.
|
* In the blocking mode, which is the default, iterator will be infinite. The call to {@link Iterator#next()} will block
|
||||||
* The call to {@link Iterator#next()} will block until a new notification
|
* until a new notification arrives. This is useful for application that runs perpetually and reacts to notifications.
|
||||||
* arrives. This is useful for application that runs perpetually and reacts
|
|
||||||
* to notifications.
|
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* In the non-blocking mode, the iterator will only report the set of
|
* In the non-blocking mode, the iterator will only report the set of notifications initially retrieved from GitHub,
|
||||||
* notifications initially retrieved from GitHub, then quit. This is useful
|
* then quit. This is useful for a batch application to process the current set of notifications.
|
||||||
* for a batch application to process the current set of notifications.
|
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GitHub#listNotifications()
|
* @see GitHub#listNotifications() GitHub#listNotifications()
|
||||||
* @see GHRepository#listNotifications()
|
* @see GHRepository#listNotifications() GHRepository#listNotifications()
|
||||||
*/
|
*/
|
||||||
public class GHNotificationStream implements Iterable<GHThread> {
|
public class GHNotificationStream implements Iterable<GHThread> {
|
||||||
private final GitHub root;
|
private final GitHub root;
|
||||||
@@ -35,13 +31,17 @@ public class GHNotificationStream implements Iterable<GHThread> {
|
|||||||
private String apiUrl;
|
private String apiUrl;
|
||||||
private boolean nonBlocking = false;
|
private boolean nonBlocking = false;
|
||||||
|
|
||||||
/*package*/ GHNotificationStream(GitHub root, String apiUrl) {
|
GHNotificationStream(GitHub root, String apiUrl) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
this.apiUrl = apiUrl;
|
this.apiUrl = apiUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should the stream include notifications that are already read?
|
* Should the stream include notifications that are already read?
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh notification stream
|
||||||
*/
|
*/
|
||||||
public GHNotificationStream read(boolean v) {
|
public GHNotificationStream read(boolean v) {
|
||||||
all = v;
|
all = v;
|
||||||
@@ -49,26 +49,47 @@ public class GHNotificationStream implements Iterable<GHThread> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should the stream be restricted to notifications in which the user
|
* Should the stream be restricted to notifications in which the user is directly participating or mentioned?
|
||||||
* is directly participating or mentioned?
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh notification stream
|
||||||
*/
|
*/
|
||||||
public GHNotificationStream participating(boolean v) {
|
public GHNotificationStream participating(boolean v) {
|
||||||
participating = v;
|
participating = v;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Since gh notification stream.
|
||||||
|
*
|
||||||
|
* @param timestamp
|
||||||
|
* the timestamp
|
||||||
|
* @return the gh notification stream
|
||||||
|
*/
|
||||||
public GHNotificationStream since(long timestamp) {
|
public GHNotificationStream since(long timestamp) {
|
||||||
return since(new Date(timestamp));
|
return since(new Date(timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Since gh notification stream.
|
||||||
|
*
|
||||||
|
* @param dt
|
||||||
|
* the dt
|
||||||
|
* @return the gh notification stream
|
||||||
|
*/
|
||||||
public GHNotificationStream since(Date dt) {
|
public GHNotificationStream since(Date dt) {
|
||||||
since = GitHub.printDate(dt);
|
since = GitHub.printDate(dt);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If set to true, {@link #iterator()} will stop iterating instead of blocking and
|
* If set to true, {@link #iterator()} will stop iterating instead of blocking and waiting for the updates to
|
||||||
* waiting for the updates to arrive.
|
* arrive.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* the v
|
||||||
|
* @return the gh notification stream
|
||||||
*/
|
*/
|
||||||
public GHNotificationStream nonBlocking(boolean v) {
|
public GHNotificationStream nonBlocking(boolean v) {
|
||||||
this.nonBlocking = v;
|
this.nonBlocking = v;
|
||||||
@@ -76,25 +97,25 @@ public class GHNotificationStream implements Iterable<GHThread> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an infinite blocking {@link Iterator} that returns
|
* Returns an infinite blocking {@link Iterator} that returns {@link GHThread} as notifications arrive.
|
||||||
* {@link GHThread} as notifications arrive.
|
|
||||||
*/
|
*/
|
||||||
public Iterator<GHThread> iterator() {
|
public Iterator<GHThread> iterator() {
|
||||||
// capture the configuration setting here
|
// capture the configuration setting here
|
||||||
final Requester req = new Requester(root).method("GET")
|
final Requester req = new Requester(root).method("GET")
|
||||||
.with("all", all).with("participating", participating).with("since", since);
|
.with("all", all)
|
||||||
|
.with("participating", participating)
|
||||||
|
.with("since", since);
|
||||||
|
|
||||||
return new Iterator<GHThread>() {
|
return new Iterator<GHThread>() {
|
||||||
/**
|
/**
|
||||||
* Stuff we've fetched but haven't returned to the caller.
|
* Stuff we've fetched but haven't returned to the caller. Newer ones first.
|
||||||
* Newer ones first.
|
|
||||||
*/
|
*/
|
||||||
private GHThread[] threads = EMPTY_ARRAY;
|
private GHThread[] threads = EMPTY_ARRAY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Next element in {@link #threads} to return. This counts down.
|
* Next element in {@link #threads} to return. This counts down.
|
||||||
*/
|
*/
|
||||||
private int idx=-1;
|
private int idx = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* threads whose updated_at is older than this should be ignored.
|
* threads whose updated_at is older than this should be ignored.
|
||||||
@@ -114,9 +135,9 @@ public class GHNotificationStream implements Iterable<GHThread> {
|
|||||||
private GHThread next;
|
private GHThread next;
|
||||||
|
|
||||||
public GHThread next() {
|
public GHThread next() {
|
||||||
if (next==null) {
|
if (next == null) {
|
||||||
next = fetch();
|
next = fetch();
|
||||||
if (next==null)
|
if (next == null)
|
||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,9 +147,9 @@ public class GHNotificationStream implements Iterable<GHThread> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
if (next==null)
|
if (next == null)
|
||||||
next = fetch();
|
next = fetch();
|
||||||
return next!=null;
|
return next != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
GHThread fetch() {
|
GHThread fetch() {
|
||||||
@@ -136,7 +157,7 @@ public class GHNotificationStream implements Iterable<GHThread> {
|
|||||||
while (true) {// loop until we get new threads to return
|
while (true) {// loop until we get new threads to return
|
||||||
|
|
||||||
// if we have fetched un-returned threads, use them first
|
// if we have fetched un-returned threads, use them first
|
||||||
while (idx>=0) {
|
while (idx >= 0) {
|
||||||
GHThread n = threads[idx--];
|
GHThread n = threads[idx--];
|
||||||
long nt = n.getUpdatedAt().getTime();
|
long nt = n.getUpdatedAt().getTime();
|
||||||
if (nt >= lastUpdated) {
|
if (nt >= lastUpdated) {
|
||||||
@@ -145,13 +166,14 @@ public class GHNotificationStream implements Iterable<GHThread> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nonBlocking && nextCheckTime>=0)
|
if (nonBlocking && nextCheckTime >= 0)
|
||||||
return null; // nothing more to report, and we aren't blocking
|
return null; // nothing more to report, and we aren't blocking
|
||||||
|
|
||||||
// observe the polling interval before making the call
|
// observe the polling interval before making the call
|
||||||
while (true) {
|
while (true) {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if (nextCheckTime < now) break;
|
if (nextCheckTime < now)
|
||||||
|
break;
|
||||||
long waitTime = Math.min(Math.max(nextCheckTime - now, 1000), 60 * 1000);
|
long waitTime = Math.min(Math.max(nextCheckTime - now, 1000), 60 * 1000);
|
||||||
Thread.sleep(waitTime);
|
Thread.sleep(waitTime);
|
||||||
}
|
}
|
||||||
@@ -159,13 +181,13 @@ public class GHNotificationStream implements Iterable<GHThread> {
|
|||||||
req.setHeader("If-Modified-Since", lastModified);
|
req.setHeader("If-Modified-Since", lastModified);
|
||||||
|
|
||||||
threads = req.to(apiUrl, GHThread[].class);
|
threads = req.to(apiUrl, GHThread[].class);
|
||||||
if (threads==null) {
|
if (threads == null) {
|
||||||
threads = EMPTY_ARRAY; // if unmodified, we get empty array
|
threads = EMPTY_ARRAY; // if unmodified, we get empty array
|
||||||
} else {
|
} else {
|
||||||
// we get a new batch, but we want to ignore the ones that we've seen
|
// we get a new batch, but we want to ignore the ones that we've seen
|
||||||
lastUpdated++;
|
lastUpdated++;
|
||||||
}
|
}
|
||||||
idx = threads.length-1;
|
idx = threads.length - 1;
|
||||||
|
|
||||||
nextCheckTime = calcNextCheckTime();
|
nextCheckTime = calcNextCheckTime();
|
||||||
lastModified = req.getResponseHeader("Last-Modified");
|
lastModified = req.getResponseHeader("Last-Modified");
|
||||||
@@ -179,9 +201,10 @@ public class GHNotificationStream implements Iterable<GHThread> {
|
|||||||
|
|
||||||
private long calcNextCheckTime() {
|
private long calcNextCheckTime() {
|
||||||
String v = req.getResponseHeader("X-Poll-Interval");
|
String v = req.getResponseHeader("X-Poll-Interval");
|
||||||
if (v==null) v="60";
|
if (v == null)
|
||||||
|
v = "60";
|
||||||
long seconds = Integer.parseInt(v);
|
long seconds = Integer.parseInt(v);
|
||||||
return System.currentTimeMillis() + seconds*1000;
|
return System.currentTimeMillis() + seconds * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove() {
|
public void remove() {
|
||||||
@@ -190,16 +213,27 @@ public class GHNotificationStream implements Iterable<GHThread> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark as read.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void markAsRead() throws IOException {
|
public void markAsRead() throws IOException {
|
||||||
markAsRead(-1);
|
markAsRead(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks all the notifications as read.
|
* Marks all the notifications as read.
|
||||||
|
*
|
||||||
|
* @param timestamp
|
||||||
|
* the timestamp
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void markAsRead(long timestamp) throws IOException {
|
public void markAsRead(long timestamp) throws IOException {
|
||||||
final Requester req = new Requester(root).method("PUT");
|
final Requester req = new Requester(root).method("PUT");
|
||||||
if (timestamp>=0)
|
if (timestamp >= 0)
|
||||||
req.with("last_read_at", GitHub.printDate(new Date(timestamp)));
|
req.with("last_read_at", GitHub.printDate(new Date(timestamp)));
|
||||||
req.asHttpStatusCode(apiUrl);
|
req.asHttpStatusCode(apiUrl);
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/main/java/org/kohsuke/github/GHOTPRequiredException.java
Normal file
10
src/main/java/org/kohsuke/github/GHOTPRequiredException.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This exception is thrown when GitHub is requesting an OTP from the user
|
||||||
|
*
|
||||||
|
* @author Kevin Harrington mad.hephaestus@gmail.com
|
||||||
|
*/
|
||||||
|
public class GHOTPRequiredException extends GHIOException {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|||||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
import javax.annotation.CheckForNull;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -13,11 +12,13 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.CheckForNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Most (all?) domain objects in GitHub seems to have these 4 properties.
|
* Most (all?) domain objects in GitHub seems to have these 4 properties.
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
|
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
|
||||||
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
|
justification = "JSON API")
|
||||||
public abstract class GHObject {
|
public abstract class GHObject {
|
||||||
/**
|
/**
|
||||||
* Capture response HTTP headers on the state object.
|
* Capture response HTTP headers on the state object.
|
||||||
@@ -29,28 +30,35 @@ public abstract class GHObject {
|
|||||||
protected String created_at;
|
protected String created_at;
|
||||||
protected String updated_at;
|
protected String updated_at;
|
||||||
|
|
||||||
/*package*/ GHObject() {
|
GHObject() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the HTTP response headers given along with the state of this object.
|
* Returns the HTTP response headers given along with the state of this object.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Some of the HTTP headers have nothing to do with the object, for example "Cache-Control"
|
* Some of the HTTP headers have nothing to do with the object, for example "Cache-Control" and others are different
|
||||||
* and others are different depending on how this object was retrieved.
|
* depending on how this object was retrieved.
|
||||||
|
* <p>
|
||||||
|
* This method was added as a kind of hack to allow the caller to retrieve OAuth scopes and such. Use with caution.
|
||||||
|
* The method might be removed in the future.
|
||||||
*
|
*
|
||||||
* This method was added as a kind of hack to allow the caller to retrieve OAuth scopes and such.
|
* @return a map of header names to value lists
|
||||||
* Use with caution. The method might be removed in the future.
|
|
||||||
*/
|
*/
|
||||||
@CheckForNull @Deprecated
|
@CheckForNull
|
||||||
|
@Deprecated
|
||||||
public Map<String, List<String>> getResponseHeaderFields() {
|
public Map<String, List<String>> getResponseHeaderFields() {
|
||||||
return responseHeaderFields;
|
return responseHeaderFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When was this resource created?
|
* When was this resource created?
|
||||||
|
*
|
||||||
|
* @return date created
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
*/
|
*/
|
||||||
@WithBridgeMethods(value=String.class, adapterMethod="createdAtStr")
|
@WithBridgeMethods(value = String.class, adapterMethod = "createdAtStr")
|
||||||
public Date getCreatedAt() throws IOException {
|
public Date getCreatedAt() throws IOException {
|
||||||
return GitHub.parseDate(created_at);
|
return GitHub.parseDate(created_at);
|
||||||
}
|
}
|
||||||
@@ -61,51 +69,63 @@ public abstract class GHObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API URL of this object.
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return API URL of this object.
|
||||||
*/
|
*/
|
||||||
@WithBridgeMethods(value=String.class, adapterMethod="urlToString")
|
@WithBridgeMethods(value = String.class, adapterMethod = "urlToString")
|
||||||
public URL getUrl() {
|
public URL getUrl() {
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL of this object for humans, which renders some HTML.
|
* Gets html url.
|
||||||
|
*
|
||||||
|
* @return URL of this object for humans, which renders some HTML.
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
*/
|
*/
|
||||||
@WithBridgeMethods(value=String.class, adapterMethod="urlToString")
|
@WithBridgeMethods(value = String.class, adapterMethod = "urlToString")
|
||||||
public abstract URL getHtmlUrl() throws IOException;
|
public abstract URL getHtmlUrl() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When was this resource last updated?
|
* When was this resource last updated?
|
||||||
|
*
|
||||||
|
* @return updated date
|
||||||
|
* @throws IOException
|
||||||
|
* on error
|
||||||
*/
|
*/
|
||||||
public Date getUpdatedAt() throws IOException {
|
public Date getUpdatedAt() throws IOException {
|
||||||
return GitHub.parseDate(updated_at);
|
return GitHub.parseDate(updated_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unique ID number of this resource.
|
* Gets id.
|
||||||
|
*
|
||||||
|
* @return Unique ID number of this resource.
|
||||||
*/
|
*/
|
||||||
@WithBridgeMethods(value={String.class,int.class}, adapterMethod="longToStringOrInt")
|
@WithBridgeMethods(value = { String.class, int.class }, adapterMethod = "longToStringOrInt")
|
||||||
public long getId() {
|
public long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getId")
|
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getId")
|
||||||
private Object longToStringOrInt(long id, Class type) {
|
private Object longToStringOrInt(long id, Class type) {
|
||||||
if (type==String.class)
|
if (type == String.class)
|
||||||
return String.valueOf(id);
|
return String.valueOf(id);
|
||||||
if (type==int.class)
|
if (type == int.class)
|
||||||
return (int)id;
|
return (int) id;
|
||||||
throw new AssertionError("Unexpected type: "+type);
|
throw new AssertionError("Unexpected type: " + type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getHtmlUrl")
|
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getHtmlUrl")
|
||||||
private Object urlToString(URL url, Class type) {
|
private Object urlToString(URL url, Class type) {
|
||||||
return url==null ? null : url.toString();
|
return url == null ? null : url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String representation to assist debugging and inspection. The output format of this string
|
* String representation to assist debugging and inspection. The output format of this string is not a committed
|
||||||
* is not a committed part of the API and is subject to change.
|
* part of the API and is subject to change.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
@@ -134,7 +154,7 @@ public abstract class GHObject {
|
|||||||
if (value instanceof GitHub)
|
if (value instanceof GitHub)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
super.append(buffer,fieldName,value,fullDetail);
|
super.append(buffer, fieldName, value, fullDetail);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ class GHOrgHook extends GHHook {
|
|||||||
/**
|
/**
|
||||||
* Organization that the hook belongs to.
|
* Organization that the hook belongs to.
|
||||||
*/
|
*/
|
||||||
/*package*/ transient GHOrganization organization;
|
transient GHOrganization organization;
|
||||||
|
|
||||||
/*package*/ GHOrgHook wrap(GHOrganization owner) {
|
GHOrgHook wrap(GHOrganization owner) {
|
||||||
this.organization = owner;
|
this.organization = owner;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,84 +10,135 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import static org.kohsuke.github.Previews.INERTIA;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The type GHOrganization.
|
||||||
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public class GHOrganization extends GHPerson {
|
public class GHOrganization extends GHPerson {
|
||||||
/*package*/ GHOrganization wrapUp(GitHub root) {
|
GHOrganization wrapUp(GitHub root) {
|
||||||
return (GHOrganization)super.wrapUp(root);
|
return (GHOrganization) super.wrapUp(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new repository.
|
* Creates a new repository.
|
||||||
*
|
*
|
||||||
* @return
|
* @param name
|
||||||
* Newly created repository.
|
* the name
|
||||||
* @deprecated
|
* @param description
|
||||||
* Use {@link #createRepository(String)} that uses a builder pattern to let you control every aspect.
|
* the description
|
||||||
|
* @param homepage
|
||||||
|
* the homepage
|
||||||
|
* @param team
|
||||||
|
* the team
|
||||||
|
* @param isPublic
|
||||||
|
* the is public
|
||||||
|
* @return Newly created repository.
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @deprecated Use {@link #createRepository(String)} that uses a builder pattern to let you control every aspect.
|
||||||
*/
|
*/
|
||||||
public GHRepository createRepository(String name, String description, String homepage, String team, boolean isPublic) throws IOException {
|
public GHRepository createRepository(String name,
|
||||||
|
String description,
|
||||||
|
String homepage,
|
||||||
|
String team,
|
||||||
|
boolean isPublic) throws IOException {
|
||||||
GHTeam t = getTeams().get(team);
|
GHTeam t = getTeams().get(team);
|
||||||
if (t==null)
|
if (t == null)
|
||||||
throw new IllegalArgumentException("No such team: "+team);
|
throw new IllegalArgumentException("No such team: " + team);
|
||||||
return createRepository(name, description, homepage, t, isPublic);
|
return createRepository(name, description, homepage, t, isPublic);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* Create repository gh repository.
|
||||||
* Use {@link #createRepository(String)} that uses a builder pattern to let you control every aspect.
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @param description
|
||||||
|
* the description
|
||||||
|
* @param homepage
|
||||||
|
* the homepage
|
||||||
|
* @param team
|
||||||
|
* the team
|
||||||
|
* @param isPublic
|
||||||
|
* the is public
|
||||||
|
* @return the gh repository
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @deprecated Use {@link #createRepository(String)} that uses a builder pattern to let you control every aspect.
|
||||||
*/
|
*/
|
||||||
public GHRepository createRepository(String name, String description, String homepage, GHTeam team, boolean isPublic) throws IOException {
|
public GHRepository createRepository(String name,
|
||||||
if (team==null)
|
String description,
|
||||||
|
String homepage,
|
||||||
|
GHTeam team,
|
||||||
|
boolean isPublic) throws IOException {
|
||||||
|
if (team == null)
|
||||||
throw new IllegalArgumentException("Invalid team");
|
throw new IllegalArgumentException("Invalid team");
|
||||||
return createRepository(name).description(description).homepage(homepage).private_(!isPublic).team(team).create();
|
return createRepository(name).description(description)
|
||||||
|
.homepage(homepage)
|
||||||
|
.private_(!isPublic)
|
||||||
|
.team(team)
|
||||||
|
.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a builder that creates a new repository.
|
* Starts a builder that creates a new repository.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* You use the returned builder to set various properties, then call {@link GHCreateRepositoryBuilder#create()}
|
* You use the returned builder to set various properties, then call {@link GHCreateRepositoryBuilder#create()} to
|
||||||
* to finally createa repository.
|
* finally createa repository.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @return the gh create repository builder
|
||||||
*/
|
*/
|
||||||
public GHCreateRepositoryBuilder createRepository(String name) {
|
public GHCreateRepositoryBuilder createRepository(String name) {
|
||||||
return new GHCreateRepositoryBuilder(root,"/orgs/"+login+"/repos",name);
|
return new GHCreateRepositoryBuilder(root, "/orgs/" + login + "/repos", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Teams by their names.
|
* Teams by their names.
|
||||||
|
*
|
||||||
|
* @return the teams
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public Map<String,GHTeam> getTeams() throws IOException {
|
public Map<String, GHTeam> getTeams() throws IOException {
|
||||||
Map<String,GHTeam> r = new TreeMap<String, GHTeam>();
|
Map<String, GHTeam> r = new TreeMap<String, GHTeam>();
|
||||||
for (GHTeam t : listTeams()) {
|
for (GHTeam t : listTeams()) {
|
||||||
r.put(t.getName(),t);
|
r.put(t.getName(), t);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List up all the teams.
|
* List up all the teams.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHTeam> listTeams() throws IOException {
|
public PagedIterable<GHTeam> listTeams() throws IOException {
|
||||||
return new PagedIterable<GHTeam>() {
|
return root.retrieve()
|
||||||
public PagedIterator<GHTeam> _iterator(int pageSize) {
|
.asPagedIterable(String.format("/orgs/%s/teams", login),
|
||||||
return new PagedIterator<GHTeam>(root.retrieve().asIterator(String.format("/orgs/%s/teams", login), GHTeam[].class, pageSize)) {
|
GHTeam[].class,
|
||||||
@Override
|
item -> item.wrapUp(GHOrganization.this));
|
||||||
protected void wrapUp(GHTeam[] page) {
|
|
||||||
for (GHTeam c : page)
|
|
||||||
c.wrapUp(GHOrganization.this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a team that has the given name in its {@link GHTeam#getName()}
|
* Finds a team that has the given name in its {@link GHTeam#getName()}
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @return the team by name
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHTeam getTeamByName(String name) throws IOException {
|
public GHTeam getTeamByName(String name) throws IOException {
|
||||||
for (GHTeam t : listTeams()) {
|
for (GHTeam t : listTeams()) {
|
||||||
if(t.getName().equals(name))
|
if (t.getName().equals(name))
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -95,21 +146,59 @@ public class GHOrganization extends GHPerson {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a team that has the given slug in its {@link GHTeam#getSlug()}
|
* Finds a team that has the given slug in its {@link GHTeam#getSlug()}
|
||||||
|
*
|
||||||
|
* @param slug
|
||||||
|
* the slug
|
||||||
|
* @return the team by slug
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHTeam getTeamBySlug(String slug) throws IOException {
|
public GHTeam getTeamBySlug(String slug) throws IOException {
|
||||||
for (GHTeam t : listTeams()) {
|
for (GHTeam t : listTeams()) {
|
||||||
if(t.getSlug().equals(slug))
|
if (t.getSlug().equals(slug))
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Member's role in an organization
|
||||||
|
*/
|
||||||
|
public enum Role {
|
||||||
|
ADMIN,
|
||||||
|
/** The user is an owner of the organization. */
|
||||||
|
MEMBER /** The user is a non-owner member of the organization. */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds (invites) a user to the organization.
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* the user
|
||||||
|
* @param role
|
||||||
|
* the role
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @see <a href=
|
||||||
|
* "https://developer.github.com/v3/orgs/members/#add-or-update-organization-membership">documentation</a>
|
||||||
|
*/
|
||||||
|
public void add(GHUser user, Role role) throws IOException {
|
||||||
|
root.retrieve()
|
||||||
|
.method("PUT")
|
||||||
|
.with("role", role.name().toLowerCase())
|
||||||
|
.to("/orgs/" + login + "/memberships/" + user.getLogin());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this organization has the specified user as a member.
|
* Checks if this organization has the specified user as a member.
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* the user
|
||||||
|
* @return the boolean
|
||||||
*/
|
*/
|
||||||
public boolean hasMember(GHUser user) {
|
public boolean hasMember(GHUser user) {
|
||||||
try {
|
try {
|
||||||
root.retrieve().to("/orgs/" + login + "/members/" + user.getLogin());
|
root.retrieve().to("/orgs/" + login + "/members/" + user.getLogin());
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException ignore) {
|
} catch (IOException ignore) {
|
||||||
return false;
|
return false;
|
||||||
@@ -117,15 +206,24 @@ public class GHOrganization extends GHPerson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a member of the organisation - which will remove them from
|
* Remove a member of the organisation - which will remove them from all teams, and remove their access to the
|
||||||
* all teams, and remove their access to the organization’s repositories.
|
* organization’s repositories.
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* the user
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void remove(GHUser user) throws IOException {
|
public void remove(GHUser user) throws IOException {
|
||||||
root.retrieve().method("DELETE").to("/orgs/" + login + "/members/" + user.getLogin());
|
root.retrieve().method("DELETE").to("/orgs/" + login + "/members/" + user.getLogin());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this organization has the specified user as a public member.
|
* Checks if this organization has the specified user as a public member.
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* the user
|
||||||
|
* @return the boolean
|
||||||
*/
|
*/
|
||||||
public boolean hasPublicMember(GHUser user) {
|
public boolean hasPublicMember(GHUser user) {
|
||||||
try {
|
try {
|
||||||
@@ -138,12 +236,22 @@ public class GHOrganization extends GHPerson {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Publicizes the membership.
|
* Publicizes the membership.
|
||||||
|
*
|
||||||
|
* @param u
|
||||||
|
* the u
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void publicize(GHUser u) throws IOException {
|
public void publicize(GHUser u) throws IOException {
|
||||||
root.retrieve().method("PUT").to("/orgs/" + login + "/public_members/" + u.getLogin(), null);
|
root.retrieve().method("PUT").to("/orgs/" + login + "/public_members/" + u.getLogin(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets members.
|
||||||
|
*
|
||||||
|
* @return the members
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
* @deprecated use {@link #listMembers()}
|
* @deprecated use {@link #listMembers()}
|
||||||
*/
|
*/
|
||||||
public List<GHUser> getMembers() throws IOException {
|
public List<GHUser> getMembers() throws IOException {
|
||||||
@@ -152,6 +260,10 @@ public class GHOrganization extends GHPerson {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* All the members of this organization.
|
* All the members of this organization.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHUser> listMembers() throws IOException {
|
public PagedIterable<GHUser> listMembers() throws IOException {
|
||||||
return listMembers("members");
|
return listMembers("members");
|
||||||
@@ -159,6 +271,10 @@ public class GHOrganization extends GHPerson {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* All the public members of this organization.
|
* All the public members of this organization.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHUser> listPublicMembers() throws IOException {
|
public PagedIterable<GHUser> listPublicMembers() throws IOException {
|
||||||
return listMembers("public_members");
|
return listMembers("public_members");
|
||||||
@@ -168,55 +284,185 @@ public class GHOrganization extends GHPerson {
|
|||||||
return listMembers(suffix, null);
|
return listMembers(suffix, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List members with filter paged iterable.
|
||||||
|
*
|
||||||
|
* @param filter
|
||||||
|
* the filter
|
||||||
|
* @return the paged iterable
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public PagedIterable<GHUser> listMembersWithFilter(String filter) throws IOException {
|
public PagedIterable<GHUser> listMembersWithFilter(String filter) throws IOException {
|
||||||
return listMembers("members", filter);
|
return listMembers("members", filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PagedIterable<GHUser> listMembers(final String suffix, final String filter) throws IOException {
|
private PagedIterable<GHUser> listMembers(final String suffix, final String filter) throws IOException {
|
||||||
return new PagedIterable<GHUser>() {
|
String filterParams = (filter == null) ? "" : ("?filter=" + filter);
|
||||||
public PagedIterator<GHUser> _iterator(int pageSize) {
|
return root.retrieve()
|
||||||
String filterParams = (filter == null) ? "" : ("?filter=" + filter);
|
.asPagedIterable(String.format("/orgs/%s/%s%s", login, suffix, filterParams),
|
||||||
return new PagedIterator<GHUser>(root.retrieve().asIterator(String.format("/orgs/%s/%s%s", login, suffix, filterParams), GHUser[].class, pageSize)) {
|
GHUser[].class,
|
||||||
@Override
|
item -> item.wrapUp(root));
|
||||||
protected void wrapUp(GHUser[] users) {
|
|
||||||
GHUser.wrap(users, root);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conceals the membership.
|
* Conceals the membership.
|
||||||
|
*
|
||||||
|
* @param u
|
||||||
|
* the u
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void conceal(GHUser u) throws IOException {
|
public void conceal(GHUser u) throws IOException {
|
||||||
root.retrieve().method("DELETE").to("/orgs/" + login + "/public_members/" + u.getLogin(), null);
|
root.retrieve().method("DELETE").to("/orgs/" + login + "/public_members/" + u.getLogin(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Permission { ADMIN, PUSH, PULL }
|
/**
|
||||||
|
* Returns the projects for this organization.
|
||||||
|
*
|
||||||
|
* @param status
|
||||||
|
* The status filter (all, open or closed).
|
||||||
|
* @return the paged iterable
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHProject> listProjects(final GHProject.ProjectStateFilter status) throws IOException {
|
||||||
|
return root.retrieve()
|
||||||
|
.withPreview(INERTIA)
|
||||||
|
.with("state", status)
|
||||||
|
.asPagedIterable(String.format("/orgs/%s/projects", login), GHProject[].class, item -> item.wrap(root));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all open projects for the organization.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHProject> listProjects() throws IOException {
|
||||||
|
return listProjects(GHProject.ProjectStateFilter.OPEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a project for the organization.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @return the gh project
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHProject createProject(String name, String body) throws IOException {
|
||||||
|
return root.retrieve()
|
||||||
|
.method("POST")
|
||||||
|
.withPreview(INERTIA)
|
||||||
|
.with("name", name)
|
||||||
|
.with("body", body)
|
||||||
|
.to(String.format("/orgs/%s/projects", login), GHProject.class)
|
||||||
|
.wrap(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The enum Permission.
|
||||||
|
*/
|
||||||
|
public enum Permission {
|
||||||
|
ADMIN, PUSH, PULL
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new team and assigns the repositories.
|
* Creates a new team and assigns the repositories.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @param p
|
||||||
|
* the p
|
||||||
|
* @param repositories
|
||||||
|
* the repositories
|
||||||
|
* @return the gh team
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @deprecated https://developer.github.com/v3/teams/#create-team deprecates permission field use
|
||||||
|
* {@link #createTeam(String, Collection)}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public GHTeam createTeam(String name, Permission p, Collection<GHRepository> repositories) throws IOException {
|
public GHTeam createTeam(String name, Permission p, Collection<GHRepository> repositories) throws IOException {
|
||||||
Requester post = new Requester(root).with("name", name).with("permission", p);
|
Requester post = new Requester(root).with("name", name).with("permission", p);
|
||||||
List<String> repo_names = new ArrayList<String>();
|
List<String> repo_names = new ArrayList<String>();
|
||||||
for (GHRepository r : repositories) {
|
for (GHRepository r : repositories) {
|
||||||
repo_names.add(r.getName());
|
repo_names.add(login + "/" + r.getName());
|
||||||
}
|
}
|
||||||
post.with("repo_names",repo_names);
|
post.with("repo_names", repo_names);
|
||||||
return post.method("POST").to("/orgs/" + login + "/teams", GHTeam.class).wrapUp(this);
|
return post.method("POST").to("/orgs/" + login + "/teams", GHTeam.class).wrapUp(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create team gh team.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @param p
|
||||||
|
* the p
|
||||||
|
* @param repositories
|
||||||
|
* the repositories
|
||||||
|
* @return the gh team
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @deprecated https://developer.github.com/v3/teams/#create-team deprecates permission field use
|
||||||
|
* {@link #createTeam(String, GHRepository...)}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public GHTeam createTeam(String name, Permission p, GHRepository... repositories) throws IOException {
|
public GHTeam createTeam(String name, Permission p, GHRepository... repositories) throws IOException {
|
||||||
return createTeam(name, p, Arrays.asList(repositories));
|
return createTeam(name, p, Arrays.asList(repositories));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List up repositories that has some open pull requests.
|
* Creates a new team and assigns the repositories.
|
||||||
*
|
*
|
||||||
* This used to be an efficient method that didn't involve traversing every repository, but now
|
* @param name
|
||||||
* it doesn't do any optimization.
|
* the name
|
||||||
|
* @param repositories
|
||||||
|
* the repositories
|
||||||
|
* @return the gh team
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHTeam createTeam(String name, Collection<GHRepository> repositories) throws IOException {
|
||||||
|
Requester post = new Requester(root).with("name", name);
|
||||||
|
List<String> repo_names = new ArrayList<String>();
|
||||||
|
for (GHRepository r : repositories) {
|
||||||
|
repo_names.add(login + "/" + r.getName());
|
||||||
|
}
|
||||||
|
post.with("repo_names", repo_names);
|
||||||
|
return post.method("POST").to("/orgs/" + login + "/teams", GHTeam.class).wrapUp(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create team gh team.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @param repositories
|
||||||
|
* the repositories
|
||||||
|
* @return the gh team
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHTeam createTeam(String name, GHRepository... repositories) throws IOException {
|
||||||
|
return createTeam(name, Arrays.asList(repositories));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List up repositories that has some open pull requests.
|
||||||
|
* <p>
|
||||||
|
* This used to be an efficient method that didn't involve traversing every repository, but now it doesn't do any
|
||||||
|
* optimization.
|
||||||
|
*
|
||||||
|
* @return the repositories with open pull requests
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public List<GHRepository> getRepositoriesWithOpenPullRequests() throws IOException {
|
public List<GHRepository> getRepositoriesWithOpenPullRequests() throws IOException {
|
||||||
List<GHRepository> r = new ArrayList<GHRepository>();
|
List<GHRepository> r = new ArrayList<GHRepository>();
|
||||||
@@ -232,6 +478,10 @@ public class GHOrganization extends GHPerson {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all the open pull requests in this organizataion.
|
* Gets all the open pull requests in this organizataion.
|
||||||
|
*
|
||||||
|
* @return the pull requests
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public List<GHPullRequest> getPullRequests() throws IOException {
|
public List<GHPullRequest> getPullRequests() throws IOException {
|
||||||
List<GHPullRequest> all = new ArrayList<GHPullRequest>();
|
List<GHPullRequest> all = new ArrayList<GHPullRequest>();
|
||||||
@@ -245,72 +495,96 @@ public class GHOrganization extends GHPerson {
|
|||||||
* Lists events performed by a user (this includes private events if the caller is authenticated.
|
* Lists events performed by a user (this includes private events if the caller is authenticated.
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHEventInfo> listEvents() throws IOException {
|
public PagedIterable<GHEventInfo> listEvents() throws IOException {
|
||||||
return new PagedIterable<GHEventInfo>() {
|
return root.retrieve()
|
||||||
public PagedIterator<GHEventInfo> _iterator(int pageSize) {
|
.asPagedIterable(String.format("/orgs/%s/events", login),
|
||||||
return new PagedIterator<GHEventInfo>(root.retrieve().asIterator(String.format("/orgs/%s/events", login), GHEventInfo[].class, pageSize)) {
|
GHEventInfo[].class,
|
||||||
@Override
|
item -> item.wrapUp(root));
|
||||||
protected void wrapUp(GHEventInfo[] page) {
|
|
||||||
for (GHEventInfo c : page)
|
|
||||||
c.wrapUp(root);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists up all the repositories using the specified page size.
|
* Lists up all the repositories using the specified page size.
|
||||||
*
|
*
|
||||||
* @param pageSize size for each page of items returned by GitHub. Maximum page size is 100.
|
* @param pageSize
|
||||||
|
* size for each page of items returned by GitHub. Maximum page size is 100.
|
||||||
*
|
*
|
||||||
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
|
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
||||||
return new PagedIterable<GHRepository>() {
|
return root.retrieve()
|
||||||
public PagedIterator<GHRepository> _iterator(int pageSize) {
|
.asPagedIterable("/orgs/" + login + "/repos", GHRepository[].class, item -> item.wrap(root))
|
||||||
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/orgs/" + login + "/repos", GHRepository[].class, pageSize)) {
|
.withPageSize(pageSize);
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHRepository[] page) {
|
|
||||||
for (GHRepository c : page)
|
|
||||||
c.wrap(root);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}.withPageSize(pageSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the currently configured hooks.
|
* Retrieves the currently configured hooks.
|
||||||
|
*
|
||||||
|
* @return the hooks
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public List<GHHook> getHooks() throws IOException {
|
public List<GHHook> getHooks() throws IOException {
|
||||||
return GHHooks.orgContext(this).getHooks();
|
return GHHooks.orgContext(this).getHooks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets hook.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* the id
|
||||||
|
* @return the hook
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHHook getHook(int id) throws IOException {
|
public GHHook getHook(int id) throws IOException {
|
||||||
return GHHooks.orgContext(this).getHook(id);
|
return GHHooks.orgContext(this).getHook(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* See https://api.github.com/hooks for possible names and their configuration scheme. TODO: produce type-safe
|
||||||
* See https://api.github.com/hooks for possible names and their configuration scheme.
|
* binding
|
||||||
* TODO: produce type-safe binding
|
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* Type of the hook to be created. See https://api.github.com/hooks for possible names.
|
* Type of the hook to be created. See https://api.github.com/hooks for possible names.
|
||||||
* @param config
|
* @param config
|
||||||
* The configuration hash.
|
* The configuration hash.
|
||||||
* @param events
|
* @param events
|
||||||
* Can be null. Types of events to hook into.
|
* Can be null. Types of events to hook into.
|
||||||
|
* @param active
|
||||||
|
* the active
|
||||||
|
* @return the gh hook
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHHook createHook(String name, Map<String,String> config, Collection<GHEvent> events, boolean active) throws IOException {
|
public GHHook createHook(String name, Map<String, String> config, Collection<GHEvent> events, boolean active)
|
||||||
|
throws IOException {
|
||||||
return GHHooks.orgContext(this).createHook(name, config, events, active);
|
return GHHooks.orgContext(this).createHook(name, config, events, active);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create web hook gh hook.
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* the url
|
||||||
|
* @param events
|
||||||
|
* the events
|
||||||
|
* @return the gh hook
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHHook createWebHook(URL url, Collection<GHEvent> events) throws IOException {
|
public GHHook createWebHook(URL url, Collection<GHEvent> events) throws IOException {
|
||||||
return createHook("web", Collections.singletonMap("url", url.toExternalForm()),events,true);
|
return createHook("web", Collections.singletonMap("url", url.toExternalForm()), events, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create web hook gh hook.
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* the url
|
||||||
|
* @return the gh hook
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHHook createWebHook(URL url) throws IOException {
|
public GHHook createWebHook(URL url) throws IOException {
|
||||||
return createWebHook(url, null);
|
return createWebHook(url, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,24 +28,37 @@ import java.util.Locale;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Permission for a user in a repository.
|
* Permission for a user in a repository.
|
||||||
|
*
|
||||||
* @see <a href="https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level">API</a>
|
* @see <a href="https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level">API</a>
|
||||||
*/
|
*/
|
||||||
/*package*/ class GHPermission {
|
class GHPermission {
|
||||||
|
|
||||||
private String permission;
|
private String permission;
|
||||||
private GHUser user;
|
private GHUser user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets permission.
|
||||||
|
*
|
||||||
* @return one of {@code admin}, {@code write}, {@code read}, or {@code none}
|
* @return one of {@code admin}, {@code write}, {@code read}, or {@code none}
|
||||||
*/
|
*/
|
||||||
public String getPermission() {
|
public String getPermission() {
|
||||||
return permission;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets permission type.
|
||||||
|
*
|
||||||
|
* @return the permission type
|
||||||
|
*/
|
||||||
public GHPermissionType getPermissionType() {
|
public GHPermissionType getPermissionType() {
|
||||||
return Enum.valueOf(GHPermissionType.class, permission.toUpperCase(Locale.ENGLISH));
|
return Enum.valueOf(GHPermissionType.class, permission.toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets user.
|
||||||
|
*
|
||||||
|
* @return the user
|
||||||
|
*/
|
||||||
public GHUser getUser() {
|
public GHUser getUser() {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The enum GHPermissionType.
|
||||||
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public enum GHPermissionType {
|
public enum GHPermissionType {
|
||||||
ADMIN,
|
ADMIN, WRITE, READ, NONE
|
||||||
WRITE,
|
|
||||||
READ,
|
|
||||||
NONE
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,32 +13,35 @@ import java.util.TreeMap;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Common part of {@link GHUser} and {@link GHOrganization}.
|
* Common part of {@link GHUser} and {@link GHOrganization}.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public abstract class GHPerson extends GHObject {
|
public abstract class GHPerson extends GHObject {
|
||||||
/*package almost final*/ GitHub root;
|
/* package almost final */ GitHub root;
|
||||||
|
|
||||||
// core data fields that exist even for "small" user data (such as the user info in pull request)
|
// core data fields that exist even for "small" user data (such as the user info in pull request)
|
||||||
protected String login, avatar_url, gravatar_id;
|
protected String login, avatar_url, gravatar_id;
|
||||||
|
|
||||||
// other fields (that only show up in full data)
|
// other fields (that only show up in full data)
|
||||||
protected String location,blog,email,name,company;
|
protected String location, blog, email, name, company;
|
||||||
protected String html_url;
|
protected String html_url;
|
||||||
protected int followers,following,public_repos,public_gists;
|
protected int followers, following, public_repos, public_gists;
|
||||||
|
|
||||||
/*package*/ GHPerson wrapUp(GitHub root) {
|
GHPerson wrapUp(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fully populate the data by retrieving missing data.
|
* Fully populate the data by retrieving missing data.
|
||||||
*
|
* <p>
|
||||||
* Depending on the original API call where this object is created, it may not contain everything.
|
* Depending on the original API call where this object is created, it may not contain everything.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
protected synchronized void populate() throws IOException {
|
protected synchronized void populate() throws IOException {
|
||||||
if (created_at!=null) {
|
if (created_at != null) {
|
||||||
return; // already populated
|
return; // already populated
|
||||||
}
|
}
|
||||||
if (root == null || root.isOffline()) {
|
if (root == null || root.isOffline()) {
|
||||||
@@ -51,64 +54,66 @@ public abstract class GHPerson extends GHObject {
|
|||||||
* Gets the public repositories this user owns.
|
* Gets the public repositories this user owns.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* To list your own repositories, including private repositories,
|
* To list your own repositories, including private repositories, use {@link GHMyself#listRepositories()}
|
||||||
* use {@link GHMyself#listRepositories()}
|
*
|
||||||
|
* @return the repositories
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public synchronized Map<String,GHRepository> getRepositories() throws IOException {
|
public synchronized Map<String, GHRepository> getRepositories() throws IOException {
|
||||||
Map<String,GHRepository> repositories = new TreeMap<String, GHRepository>();
|
Map<String, GHRepository> repositories = new TreeMap<String, GHRepository>();
|
||||||
for (GHRepository r : listRepositories(100)) {
|
for (GHRepository r : listRepositories(100)) {
|
||||||
repositories.put(r.getName(),r);
|
repositories.put(r.getName(), r);
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableMap(repositories);
|
return Collections.unmodifiableMap(repositories);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists up all the repositories using a 30 items page size.
|
* Lists up all the repositories using a 30 items page size.
|
||||||
*
|
* <p>
|
||||||
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
|
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHRepository> listRepositories() {
|
public PagedIterable<GHRepository> listRepositories() {
|
||||||
return listRepositories(30);
|
return listRepositories(30);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists up all the repositories using the specified page size.
|
* Lists up all the repositories using the specified page size.
|
||||||
*
|
*
|
||||||
* @param pageSize size for each page of items returned by GitHub. Maximum page size is 100.
|
* @param pageSize
|
||||||
*
|
* size for each page of items returned by GitHub. Maximum page size is 100. Unlike
|
||||||
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
|
* {@link #getRepositories()}, this does not wait until all the repositories are returned.
|
||||||
|
* @return the paged iterable
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
||||||
return new PagedIterable<GHRepository>() {
|
return root.retrieve()
|
||||||
public PagedIterator<GHRepository> _iterator(int pageSize) {
|
.asPagedIterable("/users/" + login + "/repos", GHRepository[].class, item -> item.wrap(root))
|
||||||
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/users/" + login + "/repos", GHRepository[].class, pageSize)) {
|
.withPageSize(pageSize);
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHRepository[] page) {
|
|
||||||
for (GHRepository c : page)
|
|
||||||
c.wrap(root);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}.withPageSize(pageSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads repository list in a paginated fashion.
|
* Loads repository list in a paginated fashion.
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* For a person with a lot of repositories, GitHub returns the list of repositories in a paginated fashion.
|
|
||||||
* Unlike {@link #getRepositories()}, this method allows the caller to start processing data as it arrives.
|
|
||||||
*
|
|
||||||
* Every {@link Iterator#next()} call results in I/O. Exceptions that occur during the processing is wrapped
|
|
||||||
* into {@link Error}.
|
|
||||||
*
|
*
|
||||||
* @deprecated
|
* <p>
|
||||||
* Use {@link #listRepositories()}
|
* For a person with a lot of repositories, GitHub returns the list of repositories in a paginated fashion. Unlike
|
||||||
|
* {@link #getRepositories()}, this method allows the caller to start processing data as it arrives.
|
||||||
|
* <p>
|
||||||
|
* Every {@link Iterator#next()} call results in I/O. Exceptions that occur during the processing is wrapped into
|
||||||
|
* {@link Error}.
|
||||||
|
*
|
||||||
|
* @param pageSize
|
||||||
|
* the page size
|
||||||
|
* @return the iterable
|
||||||
|
* @deprecated Use {@link #listRepositories()}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public synchronized Iterable<List<GHRepository>> iterateRepositories(final int pageSize) {
|
public synchronized Iterable<List<GHRepository>> iterateRepositories(final int pageSize) {
|
||||||
return new Iterable<List<GHRepository>>() {
|
return new Iterable<List<GHRepository>>() {
|
||||||
public Iterator<List<GHRepository>> iterator() {
|
public Iterator<List<GHRepository>> iterator() {
|
||||||
final Iterator<GHRepository[]> pager = root.retrieve().asIterator("/users/" + login + "/repos",GHRepository[].class, pageSize);
|
final Iterator<GHRepository[]> pager = root.retrieve()
|
||||||
|
.asIterator("/users/" + login + "/repos", GHRepository[].class, pageSize);
|
||||||
|
|
||||||
return new Iterator<List<GHRepository>>() {
|
return new Iterator<List<GHRepository>>() {
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
@@ -131,9 +136,13 @@ public abstract class GHPerson extends GHObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets repository.
|
||||||
*
|
*
|
||||||
* @return
|
* @param name
|
||||||
* null if the repository was not found
|
* the name
|
||||||
|
* @return null if the repository was not found
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHRepository getRepository(String name) throws IOException {
|
public GHRepository getRepository(String name) throws IOException {
|
||||||
try {
|
try {
|
||||||
@@ -145,33 +154,41 @@ public abstract class GHPerson extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists events for an organization or an user.
|
* Lists events for an organization or an user.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public abstract PagedIterable<GHEventInfo> listEvents() throws IOException;
|
public abstract PagedIterable<GHEventInfo> listEvents() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gravatar ID of this user, like 0cb9832a01c22c083390f3c5dcb64105
|
* Gravatar ID of this user, like 0cb9832a01c22c083390f3c5dcb64105
|
||||||
*
|
*
|
||||||
* @deprecated
|
* @return the gravatar id
|
||||||
* No longer available in the v3 API.
|
* @deprecated No longer available in the v3 API.
|
||||||
*/
|
*/
|
||||||
public String getGravatarId() {
|
public String getGravatarId() {
|
||||||
return gravatar_id;
|
return gravatar_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a string like 'https://secure.gravatar.com/avatar/0cb9832a01c22c083390f3c5dcb64105'
|
* Returns a string like 'https://secure.gravatar.com/avatar/0cb9832a01c22c083390f3c5dcb64105' that indicates the
|
||||||
* that indicates the avatar image URL.
|
* avatar image URL.
|
||||||
|
*
|
||||||
|
* @return the avatar url
|
||||||
*/
|
*/
|
||||||
public String getAvatarUrl() {
|
public String getAvatarUrl() {
|
||||||
if (avatar_url!=null)
|
if (avatar_url != null)
|
||||||
return avatar_url;
|
return avatar_url;
|
||||||
if (gravatar_id!=null)
|
if (gravatar_id != null)
|
||||||
return "https://secure.gravatar.com/avatar/"+gravatar_id;
|
return "https://secure.gravatar.com/avatar/" + gravatar_id;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the login ID of this user, like 'kohsuke'
|
* Gets the login ID of this user, like 'kohsuke'
|
||||||
|
*
|
||||||
|
* @return the login
|
||||||
*/
|
*/
|
||||||
public String getLogin() {
|
public String getLogin() {
|
||||||
return login;
|
return login;
|
||||||
@@ -179,6 +196,10 @@ public abstract class GHPerson extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the human-readable name of the user, like "Kohsuke Kawaguchi"
|
* Gets the human-readable name of the user, like "Kohsuke Kawaguchi"
|
||||||
|
*
|
||||||
|
* @return the name
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public String getName() throws IOException {
|
public String getName() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
@@ -187,6 +208,10 @@ public abstract class GHPerson extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the company name of this user, like "Sun Microsystems, Inc."
|
* Gets the company name of this user, like "Sun Microsystems, Inc."
|
||||||
|
*
|
||||||
|
* @return the company
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public String getCompany() throws IOException {
|
public String getCompany() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
@@ -195,6 +220,10 @@ public abstract class GHPerson extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the location of this user, like "Santa Clara, California"
|
* Gets the location of this user, like "Santa Clara, California"
|
||||||
|
*
|
||||||
|
* @return the location
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public String getLocation() throws IOException {
|
public String getLocation() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
@@ -213,6 +242,10 @@ public abstract class GHPerson extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the blog URL of this user.
|
* Gets the blog URL of this user.
|
||||||
|
*
|
||||||
|
* @return the blog
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public String getBlog() throws IOException {
|
public String getBlog() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
@@ -226,27 +259,59 @@ public abstract class GHPerson extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the e-mail address of the user.
|
* Gets the e-mail address of the user.
|
||||||
|
*
|
||||||
|
* @return the email
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public String getEmail() throws IOException {
|
public String getEmail() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets public gist count.
|
||||||
|
*
|
||||||
|
* @return the public gist count
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public int getPublicGistCount() throws IOException {
|
public int getPublicGistCount() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return public_gists;
|
return public_gists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets public repo count.
|
||||||
|
*
|
||||||
|
* @return the public repo count
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public int getPublicRepoCount() throws IOException {
|
public int getPublicRepoCount() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return public_repos;
|
return public_repos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets following count.
|
||||||
|
*
|
||||||
|
* @return the following count
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public int getFollowingCount() throws IOException {
|
public int getFollowingCount() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return following;
|
return following;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets followers count.
|
||||||
|
*
|
||||||
|
* @return the followers count
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public int getFollowersCount() throws IOException {
|
public int getFollowersCount() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return followers;
|
return followers;
|
||||||
|
|||||||
@@ -6,38 +6,73 @@ import java.util.HashSet;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set of {@link GHPerson} with helper lookup methods.
|
* Set of {@link GHPerson} with helper lookup methods.
|
||||||
*
|
*
|
||||||
|
* @param <T>
|
||||||
|
* the type parameter
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public class GHPersonSet<T extends GHPerson> extends HashSet<T> {
|
public class GHPersonSet<T extends GHPerson> extends HashSet<T> {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Gh person set.
|
||||||
|
*/
|
||||||
public GHPersonSet() {
|
public GHPersonSet() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Gh person set.
|
||||||
|
*
|
||||||
|
* @param c
|
||||||
|
* the c
|
||||||
|
*/
|
||||||
public GHPersonSet(Collection<? extends T> c) {
|
public GHPersonSet(Collection<? extends T> c) {
|
||||||
super(c);
|
super(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Gh person set.
|
||||||
|
*
|
||||||
|
* @param c
|
||||||
|
* the c
|
||||||
|
*/
|
||||||
public GHPersonSet(T... c) {
|
public GHPersonSet(T... c) {
|
||||||
super(Arrays.asList(c));
|
super(Arrays.asList(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Gh person set.
|
||||||
|
*
|
||||||
|
* @param initialCapacity
|
||||||
|
* the initial capacity
|
||||||
|
* @param loadFactor
|
||||||
|
* the load factor
|
||||||
|
*/
|
||||||
public GHPersonSet(int initialCapacity, float loadFactor) {
|
public GHPersonSet(int initialCapacity, float loadFactor) {
|
||||||
super(initialCapacity, loadFactor);
|
super(initialCapacity, loadFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Gh person set.
|
||||||
|
*
|
||||||
|
* @param initialCapacity
|
||||||
|
* the initial capacity
|
||||||
|
*/
|
||||||
public GHPersonSet(int initialCapacity) {
|
public GHPersonSet(int initialCapacity) {
|
||||||
super(initialCapacity);
|
super(initialCapacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the item by its login.
|
* Finds the item by its login.
|
||||||
|
*
|
||||||
|
* @param login
|
||||||
|
* the login
|
||||||
|
* @return the t
|
||||||
*/
|
*/
|
||||||
public T byLogin(String login) {
|
public T byLogin(String login) {
|
||||||
for (T t : this)
|
for (T t : this)
|
||||||
if (t.getLogin().equals(login))
|
if (t.getLogin().equals(login))
|
||||||
return t;
|
return t;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
309
src/main/java/org/kohsuke/github/GHProject.java
Normal file
309
src/main/java/org/kohsuke/github/GHProject.java
Normal file
@@ -0,0 +1,309 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright 2018 Martin van Zijl.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import static org.kohsuke.github.Previews.INERTIA;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A GitHub project.
|
||||||
|
*
|
||||||
|
* @author Martin van Zijl
|
||||||
|
* @see <a href="https://developer.github.com/v3/projects/">Projects</a>
|
||||||
|
*/
|
||||||
|
public class GHProject extends GHObject {
|
||||||
|
protected GitHub root;
|
||||||
|
protected GHObject owner;
|
||||||
|
|
||||||
|
private String owner_url;
|
||||||
|
private String html_url;
|
||||||
|
private String node_id;
|
||||||
|
private String name;
|
||||||
|
private String body;
|
||||||
|
private int number;
|
||||||
|
private String state;
|
||||||
|
private GHUser creator;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URL getHtmlUrl() throws IOException {
|
||||||
|
return GitHub.parseURL(html_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets root.
|
||||||
|
*
|
||||||
|
* @return the root
|
||||||
|
*/
|
||||||
|
public GitHub getRoot() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets owner.
|
||||||
|
*
|
||||||
|
* @return the owner
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHObject getOwner() throws IOException {
|
||||||
|
if (owner == null) {
|
||||||
|
try {
|
||||||
|
if (owner_url.contains("/orgs/")) {
|
||||||
|
owner = root.retrieve().to(getOwnerUrl().getPath(), GHOrganization.class).wrapUp(root);
|
||||||
|
} else if (owner_url.contains("/users/")) {
|
||||||
|
owner = root.retrieve().to(getOwnerUrl().getPath(), GHUser.class).wrapUp(root);
|
||||||
|
} else if (owner_url.contains("/repos/")) {
|
||||||
|
owner = root.retrieve().to(getOwnerUrl().getPath(), GHRepository.class).wrap(root);
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets owner url.
|
||||||
|
*
|
||||||
|
* @return the owner url
|
||||||
|
*/
|
||||||
|
public URL getOwnerUrl() {
|
||||||
|
return GitHub.parseURL(owner_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets node id.
|
||||||
|
*
|
||||||
|
* @return the node id
|
||||||
|
*/
|
||||||
|
public String getNode_id() {
|
||||||
|
return node_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets name.
|
||||||
|
*
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets body.
|
||||||
|
*
|
||||||
|
* @return the body
|
||||||
|
*/
|
||||||
|
public String getBody() {
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets number.
|
||||||
|
*
|
||||||
|
* @return the number
|
||||||
|
*/
|
||||||
|
public int getNumber() {
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets state.
|
||||||
|
*
|
||||||
|
* @return the state
|
||||||
|
*/
|
||||||
|
public ProjectState getState() {
|
||||||
|
return Enum.valueOf(ProjectState.class, state.toUpperCase(Locale.ENGLISH));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets creator.
|
||||||
|
*
|
||||||
|
* @return the creator
|
||||||
|
*/
|
||||||
|
public GHUser getCreator() {
|
||||||
|
return creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap gh project.
|
||||||
|
*
|
||||||
|
* @param repo
|
||||||
|
* the repo
|
||||||
|
* @return the gh project
|
||||||
|
*/
|
||||||
|
public GHProject wrap(GHRepository repo) {
|
||||||
|
this.owner = repo;
|
||||||
|
this.root = repo.root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap gh project.
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* the root
|
||||||
|
* @return the gh project
|
||||||
|
*/
|
||||||
|
public GHProject wrap(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void edit(String key, Object value) throws IOException {
|
||||||
|
new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets api route.
|
||||||
|
*
|
||||||
|
* @return the api route
|
||||||
|
*/
|
||||||
|
protected String getApiRoute() {
|
||||||
|
return "/projects/" + id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets name.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void setName(String name) throws IOException {
|
||||||
|
edit("name", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets body.
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void setBody(String body) throws IOException {
|
||||||
|
edit("body", body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The enum ProjectState.
|
||||||
|
*/
|
||||||
|
public enum ProjectState {
|
||||||
|
OPEN, CLOSED
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets state.
|
||||||
|
*
|
||||||
|
* @param state
|
||||||
|
* the state
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void setState(ProjectState state) throws IOException {
|
||||||
|
edit("state", state.toString().toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The enum ProjectStateFilter.
|
||||||
|
*/
|
||||||
|
public static enum ProjectStateFilter {
|
||||||
|
ALL, OPEN, CLOSED
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the permission level that all members of the project's organization will have on this project. Only
|
||||||
|
* applicable for organization-owned projects.
|
||||||
|
*
|
||||||
|
* @param permission
|
||||||
|
* the permission
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void setOrganizationPermission(GHPermissionType permission) throws IOException {
|
||||||
|
edit("organization_permission", permission.toString().toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets visibility of the project within the organization. Only applicable for organization-owned projects.
|
||||||
|
*
|
||||||
|
* @param isPublic
|
||||||
|
* the is public
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void setPublic(boolean isPublic) throws IOException {
|
||||||
|
edit("public", isPublic);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void delete() throws IOException {
|
||||||
|
new Requester(root).withPreview(INERTIA).method("DELETE").to(getApiRoute());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List columns paged iterable.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHProjectColumn> listColumns() throws IOException {
|
||||||
|
final GHProject project = this;
|
||||||
|
return root.retrieve()
|
||||||
|
.withPreview(INERTIA)
|
||||||
|
.asPagedIterable(String.format("/projects/%d/columns", id),
|
||||||
|
GHProjectColumn[].class,
|
||||||
|
item -> item.wrap(project));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create column gh project column.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @return the gh project column
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHProjectColumn createColumn(String name) throws IOException {
|
||||||
|
return root.retrieve()
|
||||||
|
.method("POST")
|
||||||
|
.withPreview(INERTIA)
|
||||||
|
.with("name", name)
|
||||||
|
.to(String.format("/projects/%d/columns", id), GHProjectColumn.class)
|
||||||
|
.wrap(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
222
src/main/java/org/kohsuke/github/GHProjectCard.java
Normal file
222
src/main/java/org/kohsuke/github/GHProjectCard.java
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import static org.kohsuke.github.Previews.INERTIA;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type GHProjectCard.
|
||||||
|
*
|
||||||
|
* @author Gunnar Skjold
|
||||||
|
*/
|
||||||
|
public class GHProjectCard extends GHObject {
|
||||||
|
private GitHub root;
|
||||||
|
private GHProject project;
|
||||||
|
private GHProjectColumn column;
|
||||||
|
|
||||||
|
private String note;
|
||||||
|
private GHUser creator;
|
||||||
|
private String content_url, project_url, column_url;
|
||||||
|
private boolean archived;
|
||||||
|
|
||||||
|
public URL getHtmlUrl() throws IOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap gh project card.
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* the root
|
||||||
|
* @return the gh project card
|
||||||
|
*/
|
||||||
|
public GHProjectCard wrap(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap gh project card.
|
||||||
|
*
|
||||||
|
* @param column
|
||||||
|
* the column
|
||||||
|
* @return the gh project card
|
||||||
|
*/
|
||||||
|
public GHProjectCard wrap(GHProjectColumn column) {
|
||||||
|
this.column = column;
|
||||||
|
this.project = column.project;
|
||||||
|
this.root = column.root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets root.
|
||||||
|
*
|
||||||
|
* @return the root
|
||||||
|
*/
|
||||||
|
public GitHub getRoot() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets project.
|
||||||
|
*
|
||||||
|
* @return the project
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHProject getProject() throws IOException {
|
||||||
|
if (project == null) {
|
||||||
|
try {
|
||||||
|
project = root.retrieve().to(getProjectUrl().getPath(), GHProject.class).wrap(root);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets column.
|
||||||
|
*
|
||||||
|
* @return the column
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHProjectColumn getColumn() throws IOException {
|
||||||
|
if (column == null) {
|
||||||
|
try {
|
||||||
|
column = root.retrieve().to(getColumnUrl().getPath(), GHProjectColumn.class).wrap(root);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets content.
|
||||||
|
*
|
||||||
|
* @return the content
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHIssue getContent() throws IOException {
|
||||||
|
if (StringUtils.isEmpty(content_url))
|
||||||
|
return null;
|
||||||
|
try {
|
||||||
|
if (content_url.contains("/pulls")) {
|
||||||
|
return root.retrieve().to(getContentUrl().getPath(), GHPullRequest.class).wrap(root);
|
||||||
|
} else {
|
||||||
|
return root.retrieve().to(getContentUrl().getPath(), GHIssue.class).wrap(root);
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets note.
|
||||||
|
*
|
||||||
|
* @return the note
|
||||||
|
*/
|
||||||
|
public String getNote() {
|
||||||
|
return note;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets creator.
|
||||||
|
*
|
||||||
|
* @return the creator
|
||||||
|
*/
|
||||||
|
public GHUser getCreator() {
|
||||||
|
return creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets content url.
|
||||||
|
*
|
||||||
|
* @return the content url
|
||||||
|
*/
|
||||||
|
public URL getContentUrl() {
|
||||||
|
return GitHub.parseURL(content_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets project url.
|
||||||
|
*
|
||||||
|
* @return the project url
|
||||||
|
*/
|
||||||
|
public URL getProjectUrl() {
|
||||||
|
return GitHub.parseURL(project_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets column url.
|
||||||
|
*
|
||||||
|
* @return the column url
|
||||||
|
*/
|
||||||
|
public URL getColumnUrl() {
|
||||||
|
return GitHub.parseURL(column_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is archived boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
|
public boolean isArchived() {
|
||||||
|
return archived;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets note.
|
||||||
|
*
|
||||||
|
* @param note
|
||||||
|
* the note
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void setNote(String note) throws IOException {
|
||||||
|
edit("note", note);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets archived.
|
||||||
|
*
|
||||||
|
* @param archived
|
||||||
|
* the archived
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void setArchived(boolean archived) throws IOException {
|
||||||
|
edit("archived", archived);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void edit(String key, Object value) throws IOException {
|
||||||
|
new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets api route.
|
||||||
|
*
|
||||||
|
* @return the api route
|
||||||
|
*/
|
||||||
|
protected String getApiRoute() {
|
||||||
|
return String.format("/projects/columns/cards/%d", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void delete() throws IOException {
|
||||||
|
new Requester(root).withPreview(INERTIA).method("DELETE").to(getApiRoute());
|
||||||
|
}
|
||||||
|
}
|
||||||
183
src/main/java/org/kohsuke/github/GHProjectColumn.java
Normal file
183
src/main/java/org/kohsuke/github/GHProjectColumn.java
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import static org.kohsuke.github.Previews.INERTIA;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type GHProjectColumn.
|
||||||
|
*
|
||||||
|
* @author Gunnar Skjold
|
||||||
|
*/
|
||||||
|
public class GHProjectColumn extends GHObject {
|
||||||
|
protected GitHub root;
|
||||||
|
protected GHProject project;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String project_url;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URL getHtmlUrl() throws IOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap gh project column.
|
||||||
|
*
|
||||||
|
* @param root
|
||||||
|
* the root
|
||||||
|
* @return the gh project column
|
||||||
|
*/
|
||||||
|
public GHProjectColumn wrap(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap gh project column.
|
||||||
|
*
|
||||||
|
* @param project
|
||||||
|
* the project
|
||||||
|
* @return the gh project column
|
||||||
|
*/
|
||||||
|
public GHProjectColumn wrap(GHProject project) {
|
||||||
|
this.project = project;
|
||||||
|
this.root = project.root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets root.
|
||||||
|
*
|
||||||
|
* @return the root
|
||||||
|
*/
|
||||||
|
public GitHub getRoot() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets project.
|
||||||
|
*
|
||||||
|
* @return the project
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHProject getProject() throws IOException {
|
||||||
|
if (project == null) {
|
||||||
|
try {
|
||||||
|
project = root.retrieve().to(getProjectUrl().getPath(), GHProject.class).wrap(root);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets name.
|
||||||
|
*
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets project url.
|
||||||
|
*
|
||||||
|
* @return the project url
|
||||||
|
*/
|
||||||
|
public URL getProjectUrl() {
|
||||||
|
return GitHub.parseURL(project_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets name.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void setName(String name) throws IOException {
|
||||||
|
edit("name", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void edit(String key, Object value) throws IOException {
|
||||||
|
new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets api route.
|
||||||
|
*
|
||||||
|
* @return the api route
|
||||||
|
*/
|
||||||
|
protected String getApiRoute() {
|
||||||
|
return String.format("/projects/columns/%d", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void delete() throws IOException {
|
||||||
|
new Requester(root).withPreview(INERTIA).method("DELETE").to(getApiRoute());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List cards paged iterable.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHProjectCard> listCards() throws IOException {
|
||||||
|
final GHProjectColumn column = this;
|
||||||
|
return root.retrieve()
|
||||||
|
.withPreview(INERTIA)
|
||||||
|
.asPagedIterable(String.format("/projects/columns/%d/cards", id),
|
||||||
|
GHProjectCard[].class,
|
||||||
|
item -> item.wrap(column));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create card gh project card.
|
||||||
|
*
|
||||||
|
* @param note
|
||||||
|
* the note
|
||||||
|
* @return the gh project card
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHProjectCard createCard(String note) throws IOException {
|
||||||
|
return root.retrieve()
|
||||||
|
.method("POST")
|
||||||
|
.withPreview(INERTIA)
|
||||||
|
.with("note", note)
|
||||||
|
.to(String.format("/projects/columns/%d/cards", id), GHProjectCard.class)
|
||||||
|
.wrap(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create card gh project card.
|
||||||
|
*
|
||||||
|
* @param issue
|
||||||
|
* the issue
|
||||||
|
* @return the gh project card
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHProjectCard createCard(GHIssue issue) throws IOException {
|
||||||
|
return root.retrieve()
|
||||||
|
.method("POST")
|
||||||
|
.withPreview(INERTIA)
|
||||||
|
.with("content_type", issue instanceof GHPullRequest ? "PullRequest" : "Issue")
|
||||||
|
.with("content_id", issue.getId())
|
||||||
|
.to(String.format("/projects/columns/%d/cards", id), GHProjectCard.class)
|
||||||
|
.wrap(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,23 +23,27 @@
|
|||||||
*/
|
*/
|
||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import javax.annotation.CheckForNull;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.CheckForNull;
|
||||||
|
|
||||||
|
import static org.kohsuke.github.Previews.SHADOW_CAT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A pull request.
|
* A pull request.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHRepository#getPullRequest(int)
|
* @see GHRepository#getPullRequest(int) GHRepository#getPullRequest(int)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({ "UnusedDeclaration" })
|
||||||
public class GHPullRequest extends GHIssue {
|
public class GHPullRequest extends GHIssue implements Refreshable {
|
||||||
|
|
||||||
private static final String COMMENTS_ACTION = "/comments";
|
private static final String COMMENTS_ACTION = "/comments";
|
||||||
private static final String REQUEST_REVIEWERS = "/requested_reviewers";
|
private static final String REQUEST_REVIEWERS = "/requested_reviewers";
|
||||||
@@ -53,6 +57,8 @@ public class GHPullRequest extends GHIssue {
|
|||||||
private GHUser merged_by;
|
private GHUser merged_by;
|
||||||
private int review_comments, additions, commits;
|
private int review_comments, additions, commits;
|
||||||
private boolean merged, maintainer_can_modify;
|
private boolean merged, maintainer_can_modify;
|
||||||
|
// making these package private to all for testing
|
||||||
|
boolean draft;
|
||||||
private Boolean mergeable;
|
private Boolean mergeable;
|
||||||
private int deletions;
|
private int deletions;
|
||||||
private String mergeable_state;
|
private String mergeable_state;
|
||||||
@@ -61,53 +67,63 @@ public class GHPullRequest extends GHIssue {
|
|||||||
|
|
||||||
// pull request reviewers
|
// pull request reviewers
|
||||||
private GHUser[] requested_reviewers;
|
private GHUser[] requested_reviewers;
|
||||||
|
private GHTeam[] requested_teams;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GitHub doesn't return some properties of {@link GHIssue} when requesting the GET on the 'pulls' API
|
* GitHub doesn't return some properties of {@link GHIssue} when requesting the GET on the 'pulls' API route as
|
||||||
* route as opposed to 'issues' API route. This flag remembers whether we made the GET call on the 'issues' route
|
* opposed to 'issues' API route. This flag remembers whether we made the GET call on the 'issues' route on this
|
||||||
* on this object to fill in those missing details
|
* object to fill in those missing details
|
||||||
*/
|
*/
|
||||||
private transient boolean fetchedIssueDetails;
|
private transient boolean fetchedIssueDetails;
|
||||||
|
|
||||||
|
|
||||||
GHPullRequest wrapUp(GHRepository owner) {
|
GHPullRequest wrapUp(GHRepository owner) {
|
||||||
this.wrap(owner);
|
this.wrap(owner);
|
||||||
return wrapUp(owner.root);
|
return wrapUp(owner.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
GHPullRequest wrapUp(GitHub root) {
|
GHPullRequest wrapUp(GitHub root) {
|
||||||
if (owner != null) owner.wrap(root);
|
if (owner != null)
|
||||||
if (base != null) base.wrapUp(root);
|
owner.wrap(root);
|
||||||
if (head != null) head.wrapUp(root);
|
if (base != null)
|
||||||
if (merged_by != null) merged_by.wrapUp(root);
|
base.wrapUp(root);
|
||||||
if (requested_reviewers != null) GHUser.wrap(requested_reviewers, root);
|
if (head != null)
|
||||||
|
head.wrapUp(root);
|
||||||
|
if (merged_by != null)
|
||||||
|
merged_by.wrapUp(root);
|
||||||
|
if (requested_reviewers != null)
|
||||||
|
GHUser.wrap(requested_reviewers, root);
|
||||||
|
if (requested_teams != null)
|
||||||
|
GHTeam.wrapUp(requested_teams, this);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getApiRoute() {
|
protected String getApiRoute() {
|
||||||
return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/pulls/"+number;
|
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/pulls/" + number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The URL of the patch file.
|
* The URL of the patch file. like https://github.com/jenkinsci/jenkins/pull/100.patch
|
||||||
* like https://github.com/jenkinsci/jenkins/pull/100.patch
|
*
|
||||||
|
* @return the patch url
|
||||||
*/
|
*/
|
||||||
public URL getPatchUrl() {
|
public URL getPatchUrl() {
|
||||||
return GitHub.parseURL(patch_url);
|
return GitHub.parseURL(patch_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The URL of the patch file.
|
* The URL of the patch file. like https://github.com/jenkinsci/jenkins/pull/100.patch
|
||||||
* like https://github.com/jenkinsci/jenkins/pull/100.patch
|
*
|
||||||
|
* @return the issue url
|
||||||
*/
|
*/
|
||||||
public URL getIssueUrl() {
|
public URL getIssueUrl() {
|
||||||
return GitHub.parseURL(issue_url);
|
return GitHub.parseURL(issue_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This points to where the change should be pulled into,
|
* This points to where the change should be pulled into, but I'm not really sure what exactly it means.
|
||||||
* but I'm not really sure what exactly it means.
|
*
|
||||||
|
* @return the base
|
||||||
*/
|
*/
|
||||||
public GHCommitPointer getBase() {
|
public GHCommitPointer getBase() {
|
||||||
return base;
|
return base;
|
||||||
@@ -115,24 +131,39 @@ public class GHPullRequest extends GHIssue {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The change that should be pulled. The tip of the commits to merge.
|
* The change that should be pulled. The tip of the commits to merge.
|
||||||
|
*
|
||||||
|
* @return the head
|
||||||
*/
|
*/
|
||||||
public GHCommitPointer getHead() {
|
public GHCommitPointer getHead() {
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets issue updated at.
|
||||||
|
*
|
||||||
|
* @return the issue updated at
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Date getIssueUpdatedAt() throws IOException {
|
public Date getIssueUpdatedAt() throws IOException {
|
||||||
return super.getUpdatedAt();
|
return super.getUpdatedAt();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The diff file,
|
* The diff file, like https://github.com/jenkinsci/jenkins/pull/100.diff
|
||||||
* like https://github.com/jenkinsci/jenkins/pull/100.diff
|
*
|
||||||
|
* @return the diff url
|
||||||
*/
|
*/
|
||||||
public URL getDiffUrl() {
|
public URL getDiffUrl() {
|
||||||
return GitHub.parseURL(diff_url);
|
return GitHub.parseURL(diff_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets merged at.
|
||||||
|
*
|
||||||
|
* @return the merged at
|
||||||
|
*/
|
||||||
public Date getMergedAt() {
|
public Date getMergedAt() {
|
||||||
return GitHub.parseDate(merged_at);
|
return GitHub.parseDate(merged_at);
|
||||||
}
|
}
|
||||||
@@ -157,60 +188,143 @@ public class GHPullRequest extends GHIssue {
|
|||||||
// details that are only available via get with ID
|
// details that are only available via get with ID
|
||||||
//
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets merged by.
|
||||||
|
*
|
||||||
|
* @return the merged by
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHUser getMergedBy() throws IOException {
|
public GHUser getMergedBy() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return merged_by;
|
return merged_by;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets review comments.
|
||||||
|
*
|
||||||
|
* @return the review comments
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public int getReviewComments() throws IOException {
|
public int getReviewComments() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return review_comments;
|
return review_comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets additions.
|
||||||
|
*
|
||||||
|
* @return the additions
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public int getAdditions() throws IOException {
|
public int getAdditions() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return additions;
|
return additions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets commits.
|
||||||
|
*
|
||||||
|
* @return the commits
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public int getCommits() throws IOException {
|
public int getCommits() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return commits;
|
return commits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is merged boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public boolean isMerged() throws IOException {
|
public boolean isMerged() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can maintainer modify boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public boolean canMaintainerModify() throws IOException {
|
public boolean canMaintainerModify() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return maintainer_can_modify;
|
return maintainer_can_modify;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is draft boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public boolean isDraft() throws IOException {
|
||||||
|
populate();
|
||||||
|
return draft;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this PR mergeable?
|
* Is this PR mergeable?
|
||||||
*
|
*
|
||||||
* @return
|
* @return null if the state has not been determined yet, for example when a PR is newly created. If this method is
|
||||||
* null if the state has not been determined yet, for example when a PR is newly created.
|
* called on an instance whose mergeable state is not yet known, API call is made to retrieve the latest
|
||||||
* If this method is called on an instance whose mergeable state is not yet known,
|
* state.
|
||||||
* API call is made to retrieve the latest state.
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public Boolean getMergeable() throws IOException {
|
public Boolean getMergeable() throws IOException {
|
||||||
if (mergeable==null)
|
refresh(mergeable);
|
||||||
refresh();
|
|
||||||
return mergeable;
|
return mergeable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* for test purposes only
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
Boolean getMergeableNoRefresh() throws IOException {
|
||||||
|
return mergeable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets deletions.
|
||||||
|
*
|
||||||
|
* @return the deletions
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public int getDeletions() throws IOException {
|
public int getDeletions() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return deletions;
|
return deletions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets mergeable state.
|
||||||
|
*
|
||||||
|
* @return the mergeable state
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public String getMergeableState() throws IOException {
|
public String getMergeableState() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return mergeable_state;
|
return mergeable_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets changed files.
|
||||||
|
*
|
||||||
|
* @return the changed files
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public int getChangedFiles() throws IOException {
|
public int getChangedFiles() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return changed_files;
|
return changed_files;
|
||||||
@@ -218,24 +332,48 @@ public class GHPullRequest extends GHIssue {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* See <a href="https://developer.github.com/changes/2013-04-25-deprecating-merge-commit-sha">GitHub blog post</a>
|
* See <a href="https://developer.github.com/changes/2013-04-25-deprecating-merge-commit-sha">GitHub blog post</a>
|
||||||
|
*
|
||||||
|
* @return the merge commit sha
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public String getMergeCommitSha() throws IOException {
|
public String getMergeCommitSha() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return merge_commit_sha;
|
return merge_commit_sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets requested reviewers.
|
||||||
|
*
|
||||||
|
* @return the requested reviewers
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public List<GHUser> getRequestedReviewers() throws IOException {
|
public List<GHUser> getRequestedReviewers() throws IOException {
|
||||||
populate();
|
refresh(requested_reviewers);
|
||||||
return Collections.unmodifiableList(Arrays.asList(requested_reviewers));
|
return Collections.unmodifiableList(Arrays.asList(requested_reviewers));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets requested teams.
|
||||||
|
*
|
||||||
|
* @return the requested teams
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public List<GHTeam> getRequestedTeams() throws IOException {
|
||||||
|
refresh(requested_teams);
|
||||||
|
return Collections.unmodifiableList(Arrays.asList(requested_teams));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fully populate the data by retrieving missing data.
|
* Fully populate the data by retrieving missing data.
|
||||||
*
|
*
|
||||||
* Depending on the original API call where this object is created, it may not contain everything.
|
* Depending on the original API call where this object is created, it may not contain everything.
|
||||||
*/
|
*/
|
||||||
private void populate() throws IOException {
|
private void populate() throws IOException {
|
||||||
if (mergeable_state!=null) return; // already populated
|
if (mergeable_state != null)
|
||||||
|
return; // already populated
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,96 +384,94 @@ public class GHPullRequest extends GHIssue {
|
|||||||
if (root.isOffline()) {
|
if (root.isOffline()) {
|
||||||
return; // cannot populate, will have to live with what we have
|
return; // cannot populate, will have to live with what we have
|
||||||
}
|
}
|
||||||
root.retrieve().to(url, this).wrapUp(owner);
|
root.retrieve().withPreview(SHADOW_CAT).to(url, this).wrapUp(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all the files associated to this pull request.
|
* Retrieves all the files associated to this pull request.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHPullRequestFileDetail> listFiles() {
|
public PagedIterable<GHPullRequestFileDetail> listFiles() {
|
||||||
return new PagedIterable<GHPullRequestFileDetail>() {
|
return root.retrieve()
|
||||||
public PagedIterator<GHPullRequestFileDetail> _iterator(int pageSize) {
|
.asPagedIterable(String.format("%s/files", getApiRoute()), GHPullRequestFileDetail[].class, null);
|
||||||
return new PagedIterator<GHPullRequestFileDetail>(root.retrieve().asIterator(String.format("%s/files", getApiRoute()),
|
|
||||||
GHPullRequestFileDetail[].class, pageSize)) {
|
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHPullRequestFileDetail[] page) {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all the reviews associated to this pull request.
|
* Retrieves all the reviews associated to this pull request.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHPullRequestReview> listReviews() {
|
public PagedIterable<GHPullRequestReview> listReviews() {
|
||||||
return new PagedIterable<GHPullRequestReview>() {
|
return root.retrieve()
|
||||||
public PagedIterator<GHPullRequestReview> _iterator(int pageSize) {
|
.asPagedIterable(String.format("%s/reviews", getApiRoute()),
|
||||||
return new PagedIterator<GHPullRequestReview>(root.retrieve()
|
GHPullRequestReview[].class,
|
||||||
.asIterator(String.format("%s/reviews", getApiRoute()),
|
item -> item.wrapUp(GHPullRequest.this));
|
||||||
GHPullRequestReview[].class, pageSize)) {
|
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHPullRequestReview[] page) {
|
|
||||||
for (GHPullRequestReview r: page) {
|
|
||||||
r.wrapUp(GHPullRequest.this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains all the review comments associated with this pull request.
|
* Obtains all the review comments associated with this pull request.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException {
|
public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException {
|
||||||
return new PagedIterable<GHPullRequestReviewComment>() {
|
return root.retrieve()
|
||||||
public PagedIterator<GHPullRequestReviewComment> _iterator(int pageSize) {
|
.asPagedIterable(getApiRoute() + COMMENTS_ACTION,
|
||||||
return new PagedIterator<GHPullRequestReviewComment>(root.retrieve().asIterator(getApiRoute() + COMMENTS_ACTION,
|
GHPullRequestReviewComment[].class,
|
||||||
GHPullRequestReviewComment[].class, pageSize)) {
|
item -> item.wrapUp(GHPullRequest.this));
|
||||||
protected void wrapUp(GHPullRequestReviewComment[] page) {
|
|
||||||
for (GHPullRequestReviewComment c : page)
|
|
||||||
c.wrapUp(GHPullRequest.this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all the commits associated to this pull request.
|
* Retrieves all the commits associated to this pull request.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHPullRequestCommitDetail> listCommits() {
|
public PagedIterable<GHPullRequestCommitDetail> listCommits() {
|
||||||
return new PagedIterable<GHPullRequestCommitDetail>() {
|
return root.retrieve()
|
||||||
public PagedIterator<GHPullRequestCommitDetail> _iterator(int pageSize) {
|
.asPagedIterable(String.format("%s/commits", getApiRoute()),
|
||||||
return new PagedIterator<GHPullRequestCommitDetail>(root.retrieve().asIterator(
|
GHPullRequestCommitDetail[].class,
|
||||||
String.format("%s/commits", getApiRoute()),
|
item -> item.wrapUp(GHPullRequest.this));
|
||||||
GHPullRequestCommitDetail[].class, pageSize)) {
|
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHPullRequestCommitDetail[] page) {
|
|
||||||
for (GHPullRequestCommitDetail c : page)
|
|
||||||
c.wrapUp(GHPullRequest.this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* Create review gh pull request review.
|
||||||
* Use {@link #createReview()}
|
*
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @param event
|
||||||
|
* the event
|
||||||
|
* @param comments
|
||||||
|
* the comments
|
||||||
|
* @return the gh pull request review
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @deprecated Use {@link #createReview()}
|
||||||
*/
|
*/
|
||||||
public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequestReviewState event,
|
public GHPullRequestReview createReview(String body,
|
||||||
GHPullRequestReviewComment... comments) throws IOException {
|
@CheckForNull GHPullRequestReviewState event,
|
||||||
|
GHPullRequestReviewComment... comments) throws IOException {
|
||||||
return createReview(body, event, Arrays.asList(comments));
|
return createReview(body, event, Arrays.asList(comments));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* Create review gh pull request review.
|
||||||
* Use {@link #createReview()}
|
*
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @param event
|
||||||
|
* the event
|
||||||
|
* @param comments
|
||||||
|
* the comments
|
||||||
|
* @return the gh pull request review
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @deprecated Use {@link #createReview()}
|
||||||
*/
|
*/
|
||||||
public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequestReviewState event,
|
public GHPullRequestReview createReview(String body,
|
||||||
List<GHPullRequestReviewComment> comments) throws IOException {
|
@CheckForNull GHPullRequestReviewState event,
|
||||||
|
List<GHPullRequestReviewComment> comments) throws IOException {
|
||||||
GHPullRequestReviewBuilder b = createReview().body(body);
|
GHPullRequestReviewBuilder b = createReview().body(body);
|
||||||
for (GHPullRequestReviewComment c : comments) {
|
for (GHPullRequestReviewComment c : comments) {
|
||||||
b.comment(c.getBody(), c.getPath(), c.getPosition());
|
b.comment(c.getBody(), c.getPath(), c.getPosition());
|
||||||
@@ -343,46 +479,96 @@ public class GHPullRequest extends GHIssue {
|
|||||||
return b.create();
|
return b.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create review gh pull request review builder.
|
||||||
|
*
|
||||||
|
* @return the gh pull request review builder
|
||||||
|
*/
|
||||||
public GHPullRequestReviewBuilder createReview() {
|
public GHPullRequestReviewBuilder createReview() {
|
||||||
return new GHPullRequestReviewBuilder(this);
|
return new GHPullRequestReviewBuilder(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHPullRequestReviewComment createReviewComment(String body, String sha, String path, int position) throws IOException {
|
/**
|
||||||
|
* Create review comment gh pull request review comment.
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @param sha
|
||||||
|
* the sha
|
||||||
|
* @param path
|
||||||
|
* the path
|
||||||
|
* @param position
|
||||||
|
* the position
|
||||||
|
* @return the gh pull request review comment
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public GHPullRequestReviewComment createReviewComment(String body, String sha, String path, int position)
|
||||||
|
throws IOException {
|
||||||
return new Requester(root).method("POST")
|
return new Requester(root).method("POST")
|
||||||
.with("body", body)
|
.with("body", body)
|
||||||
.with("commit_id", sha)
|
.with("commit_id", sha)
|
||||||
.with("path", path)
|
.with("path", path)
|
||||||
.with("position", position)
|
.with("position", position)
|
||||||
.to(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment.class).wrapUp(this);
|
.to(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment.class)
|
||||||
|
.wrapUp(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request reviewers.
|
||||||
|
*
|
||||||
|
* @param reviewers
|
||||||
|
* the reviewers
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public void requestReviewers(List<GHUser> reviewers) throws IOException {
|
public void requestReviewers(List<GHUser> reviewers) throws IOException {
|
||||||
new Requester(root).method("POST")
|
new Requester(root).method("POST")
|
||||||
.withLogins("reviewers", reviewers)
|
.with("reviewers", getLogins(reviewers))
|
||||||
.to(getApiRoute() + REQUEST_REVIEWERS);
|
.to(getApiRoute() + REQUEST_REVIEWERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge this pull request.
|
* Request team reviewers.
|
||||||
*
|
*
|
||||||
* The equivalent of the big green "Merge pull request" button.
|
* @param teams
|
||||||
*
|
* the teams
|
||||||
* @param msg
|
* @throws IOException
|
||||||
* Commit message. If null, the default one will be used.
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void merge(String msg) throws IOException {
|
public void requestTeamReviewers(List<GHTeam> teams) throws IOException {
|
||||||
merge(msg,null);
|
List<String> teamReviewers = new ArrayList<String>(teams.size());
|
||||||
|
for (GHTeam team : teams) {
|
||||||
|
teamReviewers.add(team.getSlug());
|
||||||
|
}
|
||||||
|
new Requester(root).method("POST").with("team_reviewers", teamReviewers).to(getApiRoute() + REQUEST_REVIEWERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge this pull request.
|
* Merge this pull request.
|
||||||
*
|
* <p>
|
||||||
* The equivalent of the big green "Merge pull request" button.
|
* The equivalent of the big green "Merge pull request" button.
|
||||||
*
|
*
|
||||||
* @param msg
|
* @param msg
|
||||||
* Commit message. If null, the default one will be used.
|
* Commit message. If null, the default one will be used.
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public void merge(String msg) throws IOException {
|
||||||
|
merge(msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge this pull request.
|
||||||
|
* <p>
|
||||||
|
* The equivalent of the big green "Merge pull request" button.
|
||||||
|
*
|
||||||
|
* @param msg
|
||||||
|
* Commit message. If null, the default one will be used.
|
||||||
* @param sha
|
* @param sha
|
||||||
* SHA that pull request head must match to allow merge.
|
* SHA that pull request head must match to allow merge.
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void merge(String msg, String sha) throws IOException {
|
public void merge(String msg, String sha) throws IOException {
|
||||||
merge(msg, sha, null);
|
merge(msg, sha, null);
|
||||||
@@ -390,13 +576,17 @@ public class GHPullRequest extends GHIssue {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge this pull request, using the specified merge method.
|
* Merge this pull request, using the specified merge method.
|
||||||
*
|
* <p>
|
||||||
* The equivalent of the big green "Merge pull request" button.
|
* The equivalent of the big green "Merge pull request" button.
|
||||||
*
|
*
|
||||||
* @param msg
|
* @param msg
|
||||||
* Commit message. If null, the default one will be used.
|
* Commit message. If null, the default one will be used.
|
||||||
|
* @param sha
|
||||||
|
* the sha
|
||||||
* @param method
|
* @param method
|
||||||
* SHA that pull request head must match to allow merge.
|
* SHA that pull request head must match to allow merge.
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void merge(String msg, String sha, MergeMethod method) throws IOException {
|
public void merge(String msg, String sha, MergeMethod method) throws IOException {
|
||||||
new Requester(root).method("PUT")
|
new Requester(root).method("PUT")
|
||||||
@@ -406,7 +596,12 @@ public class GHPullRequest extends GHIssue {
|
|||||||
.to(getApiRoute() + "/merge");
|
.to(getApiRoute() + "/merge");
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum MergeMethod{ MERGE, SQUASH, REBASE }
|
/**
|
||||||
|
* The enum MergeMethod.
|
||||||
|
*/
|
||||||
|
public enum MergeMethod {
|
||||||
|
MERGE, SQUASH, REBASE
|
||||||
|
}
|
||||||
|
|
||||||
private void fetchIssue() throws IOException {
|
private void fetchIssue() throws IOException {
|
||||||
if (!fetchedIssueDetails) {
|
if (!fetchedIssueDetails) {
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013, Luca Milanesio
|
* Copyright (c) 2013, Luca Milanesio
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@@ -30,38 +30,58 @@ import java.net.URL;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Commit detail inside a {@link GHPullRequest}.
|
* Commit detail inside a {@link GHPullRequest}.
|
||||||
*
|
*
|
||||||
* @author Luca Milanesio
|
* @author Luca Milanesio
|
||||||
* @see GHPullRequest#listCommits()
|
* @see GHPullRequest#listCommits() GHPullRequest#listCommits()
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
|
@SuppressFBWarnings(
|
||||||
"NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD"}, justification = "JSON API")
|
value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
|
||||||
|
"URF_UNREAD_FIELD" },
|
||||||
|
justification = "JSON API")
|
||||||
public class GHPullRequestCommitDetail {
|
public class GHPullRequestCommitDetail {
|
||||||
private GHPullRequest owner;
|
private GHPullRequest owner;
|
||||||
|
|
||||||
/*package*/ void wrapUp(GHPullRequest owner) {
|
void wrapUp(GHPullRequest owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The type Authorship.
|
||||||
|
*
|
||||||
* @deprecated Use {@link GitUser}
|
* @deprecated Use {@link GitUser}
|
||||||
*/
|
*/
|
||||||
public static class Authorship extends GitUser {
|
public static class Authorship extends GitUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Tree.
|
||||||
|
*/
|
||||||
public static class Tree {
|
public static class Tree {
|
||||||
String sha;
|
String sha;
|
||||||
String url;
|
String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets sha.
|
||||||
|
*
|
||||||
|
* @return the sha
|
||||||
|
*/
|
||||||
public String getSha() {
|
public String getSha() {
|
||||||
return sha;
|
return sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public URL getUrl() {
|
public URL getUrl() {
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Commit.
|
||||||
|
*/
|
||||||
public static class Commit {
|
public static class Commit {
|
||||||
Authorship author;
|
Authorship author;
|
||||||
Authorship committer;
|
Authorship committer;
|
||||||
@@ -70,46 +90,94 @@ public class GHPullRequestCommitDetail {
|
|||||||
String url;
|
String url;
|
||||||
int comment_count;
|
int comment_count;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets author.
|
||||||
|
*
|
||||||
|
* @return the author
|
||||||
|
*/
|
||||||
@WithBridgeMethods(value = Authorship.class, castRequired = true)
|
@WithBridgeMethods(value = Authorship.class, castRequired = true)
|
||||||
public GitUser getAuthor() {
|
public GitUser getAuthor() {
|
||||||
return author;
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets committer.
|
||||||
|
*
|
||||||
|
* @return the committer
|
||||||
|
*/
|
||||||
@WithBridgeMethods(value = Authorship.class, castRequired = true)
|
@WithBridgeMethods(value = Authorship.class, castRequired = true)
|
||||||
public GitUser getCommitter() {
|
public GitUser getCommitter() {
|
||||||
return committer;
|
return committer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets message.
|
||||||
|
*
|
||||||
|
* @return the message
|
||||||
|
*/
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public URL getUrl() {
|
public URL getUrl() {
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets comment count.
|
||||||
|
*
|
||||||
|
* @return the comment count
|
||||||
|
*/
|
||||||
public int getComment_count() {
|
public int getComment_count() {
|
||||||
return comment_count;
|
return comment_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets tree.
|
||||||
|
*
|
||||||
|
* @return the tree
|
||||||
|
*/
|
||||||
public Tree getTree() {
|
public Tree getTree() {
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type CommitPointer.
|
||||||
|
*/
|
||||||
public static class CommitPointer {
|
public static class CommitPointer {
|
||||||
String sha;
|
String sha;
|
||||||
String url;
|
String url;
|
||||||
String html_url;
|
String html_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public URL getUrl() {
|
public URL getUrl() {
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets html url.
|
||||||
|
*
|
||||||
|
* @return the html url
|
||||||
|
*/
|
||||||
public URL getHtml_url() {
|
public URL getHtml_url() {
|
||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets sha.
|
||||||
|
*
|
||||||
|
* @return the sha
|
||||||
|
*/
|
||||||
public String getSha() {
|
public String getSha() {
|
||||||
return sha;
|
return sha;
|
||||||
}
|
}
|
||||||
@@ -122,26 +190,56 @@ public class GHPullRequestCommitDetail {
|
|||||||
String comments_url;
|
String comments_url;
|
||||||
CommitPointer[] parents;
|
CommitPointer[] parents;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets sha.
|
||||||
|
*
|
||||||
|
* @return the sha
|
||||||
|
*/
|
||||||
public String getSha() {
|
public String getSha() {
|
||||||
return sha;
|
return sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets commit.
|
||||||
|
*
|
||||||
|
* @return the commit
|
||||||
|
*/
|
||||||
public Commit getCommit() {
|
public Commit getCommit() {
|
||||||
return commit;
|
return commit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets api url.
|
||||||
|
*
|
||||||
|
* @return the api url
|
||||||
|
*/
|
||||||
public URL getApiUrl() {
|
public URL getApiUrl() {
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets url.
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
public URL getUrl() {
|
public URL getUrl() {
|
||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets comments url.
|
||||||
|
*
|
||||||
|
* @return the comments url
|
||||||
|
*/
|
||||||
public URL getCommentsUrl() {
|
public URL getCommentsUrl() {
|
||||||
return GitHub.parseURL(comments_url);
|
return GitHub.parseURL(comments_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get parents commit pointer [ ].
|
||||||
|
*
|
||||||
|
* @return the commit pointer [ ]
|
||||||
|
*/
|
||||||
public CommitPointer[] getParents() {
|
public CommitPointer[] getParents() {
|
||||||
CommitPointer[] newValue = new CommitPointer[parents.length];
|
CommitPointer[] newValue = new CommitPointer[parents.length];
|
||||||
System.arraycopy(parents, 0, newValue, 0, parents.length);
|
System.arraycopy(parents, 0, newValue, 0, parents.length);
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
*
|
*
|
||||||
* Copyright (c) 2015, Julien Henry
|
* Copyright (c) 2015, Julien Henry
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@@ -27,9 +27,9 @@ import java.net.URL;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* File detail inside a {@link GHPullRequest}.
|
* File detail inside a {@link GHPullRequest}.
|
||||||
*
|
*
|
||||||
* @author Julien Henry
|
* @author Julien Henry
|
||||||
* @see GHPullRequest#listFiles()
|
* @see GHPullRequest#listFiles() GHPullRequest#listFiles()
|
||||||
*/
|
*/
|
||||||
public class GHPullRequestFileDetail {
|
public class GHPullRequestFileDetail {
|
||||||
|
|
||||||
@@ -45,48 +45,102 @@ public class GHPullRequestFileDetail {
|
|||||||
String patch;
|
String patch;
|
||||||
String previous_filename;
|
String previous_filename;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets sha.
|
||||||
|
*
|
||||||
|
* @return the sha
|
||||||
|
*/
|
||||||
public String getSha() {
|
public String getSha() {
|
||||||
return sha;
|
return sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets filename.
|
||||||
|
*
|
||||||
|
* @return the filename
|
||||||
|
*/
|
||||||
public String getFilename() {
|
public String getFilename() {
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets status.
|
||||||
|
*
|
||||||
|
* @return the status
|
||||||
|
*/
|
||||||
public String getStatus() {
|
public String getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets additions.
|
||||||
|
*
|
||||||
|
* @return the additions
|
||||||
|
*/
|
||||||
public int getAdditions() {
|
public int getAdditions() {
|
||||||
return additions;
|
return additions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets deletions.
|
||||||
|
*
|
||||||
|
* @return the deletions
|
||||||
|
*/
|
||||||
public int getDeletions() {
|
public int getDeletions() {
|
||||||
return deletions;
|
return deletions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets changes.
|
||||||
|
*
|
||||||
|
* @return the changes
|
||||||
|
*/
|
||||||
public int getChanges() {
|
public int getChanges() {
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets blob url.
|
||||||
|
*
|
||||||
|
* @return the blob url
|
||||||
|
*/
|
||||||
public URL getBlobUrl() {
|
public URL getBlobUrl() {
|
||||||
return GitHub.parseURL(blob_url);
|
return GitHub.parseURL(blob_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets raw url.
|
||||||
|
*
|
||||||
|
* @return the raw url
|
||||||
|
*/
|
||||||
public URL getRawUrl() {
|
public URL getRawUrl() {
|
||||||
return GitHub.parseURL(raw_url);
|
return GitHub.parseURL(raw_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets contents url.
|
||||||
|
*
|
||||||
|
* @return the contents url
|
||||||
|
*/
|
||||||
public URL getContentsUrl() {
|
public URL getContentsUrl() {
|
||||||
return GitHub.parseURL(contents_url);
|
return GitHub.parseURL(contents_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets patch.
|
||||||
|
*
|
||||||
|
* @return the patch
|
||||||
|
*/
|
||||||
public String getPatch() {
|
public String getPatch() {
|
||||||
return patch;
|
return patch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPreviousFilename()
|
/**
|
||||||
{
|
* Gets previous filename.
|
||||||
|
*
|
||||||
|
* @return the previous filename
|
||||||
|
*/
|
||||||
|
public String getPreviousFilename() {
|
||||||
return previous_filename;
|
return previous_filename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,58 +1,94 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import static org.kohsuke.github.Previews.SHADOW_CAT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists up pull requests with some filtering and sorting.
|
* Lists up pull requests with some filtering and sorting.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHRepository#queryPullRequests()
|
* @see GHRepository#queryPullRequests() GHRepository#queryPullRequests()
|
||||||
*/
|
*/
|
||||||
public class GHPullRequestQueryBuilder extends GHQueryBuilder<GHPullRequest> {
|
public class GHPullRequestQueryBuilder extends GHQueryBuilder<GHPullRequest> {
|
||||||
private final GHRepository repo;
|
private final GHRepository repo;
|
||||||
|
|
||||||
/*package*/ GHPullRequestQueryBuilder(GHRepository repo) {
|
GHPullRequestQueryBuilder(GHRepository repo) {
|
||||||
super(repo.root);
|
super(repo.root);
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* State gh pull request query builder.
|
||||||
|
*
|
||||||
|
* @param state
|
||||||
|
* the state
|
||||||
|
* @return the gh pull request query builder
|
||||||
|
*/
|
||||||
public GHPullRequestQueryBuilder state(GHIssueState state) {
|
public GHPullRequestQueryBuilder state(GHIssueState state) {
|
||||||
req.with("state",state);
|
req.with("state", state);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Head gh pull request query builder.
|
||||||
|
*
|
||||||
|
* @param head
|
||||||
|
* the head
|
||||||
|
* @return the gh pull request query builder
|
||||||
|
*/
|
||||||
public GHPullRequestQueryBuilder head(String head) {
|
public GHPullRequestQueryBuilder head(String head) {
|
||||||
req.with("head",head);
|
if (head != null && !head.contains(":")) {
|
||||||
|
head = repo.getOwnerName() + ":" + head;
|
||||||
|
}
|
||||||
|
req.with("head", head);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base gh pull request query builder.
|
||||||
|
*
|
||||||
|
* @param base
|
||||||
|
* the base
|
||||||
|
* @return the gh pull request query builder
|
||||||
|
*/
|
||||||
public GHPullRequestQueryBuilder base(String base) {
|
public GHPullRequestQueryBuilder base(String base) {
|
||||||
req.with("base",base);
|
req.with("base", base);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort gh pull request query builder.
|
||||||
|
*
|
||||||
|
* @param sort
|
||||||
|
* the sort
|
||||||
|
* @return the gh pull request query builder
|
||||||
|
*/
|
||||||
public GHPullRequestQueryBuilder sort(Sort sort) {
|
public GHPullRequestQueryBuilder sort(Sort sort) {
|
||||||
req.with("sort",sort);
|
req.with("sort", sort);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Sort { CREATED, UPDATED, POPULARITY, LONG_RUNNING }
|
/**
|
||||||
|
* The enum Sort.
|
||||||
|
*/
|
||||||
|
public enum Sort {
|
||||||
|
CREATED, UPDATED, POPULARITY, LONG_RUNNING
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Direction gh pull request query builder.
|
||||||
|
*
|
||||||
|
* @param d
|
||||||
|
* the d
|
||||||
|
* @return the gh pull request query builder
|
||||||
|
*/
|
||||||
public GHPullRequestQueryBuilder direction(GHDirection d) {
|
public GHPullRequestQueryBuilder direction(GHDirection d) {
|
||||||
req.with("direction",d);
|
req.with("direction", d);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PagedIterable<GHPullRequest> list() {
|
public PagedIterable<GHPullRequest> list() {
|
||||||
return new PagedIterable<GHPullRequest>() {
|
return req.withPreview(SHADOW_CAT)
|
||||||
public PagedIterator<GHPullRequest> _iterator(int pageSize) {
|
.asPagedIterable(repo.getApiTailUrl("pulls"), GHPullRequest[].class, item -> item.wrapUp(repo));
|
||||||
return new PagedIterator<GHPullRequest>(req.asIterator(repo.getApiTailUrl("pulls"), GHPullRequest[].class, pageSize)) {
|
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHPullRequest[] page) {
|
|
||||||
for (GHPullRequest pr : page)
|
|
||||||
pr.wrapUp(repo);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,17 +25,19 @@ package org.kohsuke.github;
|
|||||||
|
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
|
||||||
import javax.annotation.CheckForNull;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.annotation.CheckForNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Review to a pull request.
|
* Review to a pull request.
|
||||||
*
|
*
|
||||||
* @see GHPullRequest#listReviews()
|
* @see GHPullRequest#listReviews() GHPullRequest#listReviews()
|
||||||
* @see GHPullRequestReviewBuilder
|
* @see GHPullRequestReviewBuilder
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_FIELD"}, justification = "JSON API")
|
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
|
||||||
public class GHPullRequestReview extends GHObject {
|
public class GHPullRequestReview extends GHObject {
|
||||||
GHPullRequest owner;
|
GHPullRequest owner;
|
||||||
|
|
||||||
@@ -43,14 +45,17 @@ public class GHPullRequestReview extends GHObject {
|
|||||||
private GHUser user;
|
private GHUser user;
|
||||||
private String commit_id;
|
private String commit_id;
|
||||||
private GHPullRequestReviewState state;
|
private GHPullRequestReviewState state;
|
||||||
|
private String submitted_at;
|
||||||
|
|
||||||
/*package*/ GHPullRequestReview wrapUp(GHPullRequest owner) {
|
GHPullRequestReview wrapUp(GHPullRequest owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the pull request to which this review is associated.
|
* Gets the pull request to which this review is associated.
|
||||||
|
*
|
||||||
|
* @return the parent
|
||||||
*/
|
*/
|
||||||
public GHPullRequest getParent() {
|
public GHPullRequest getParent() {
|
||||||
return owner;
|
return owner;
|
||||||
@@ -58,6 +63,8 @@ public class GHPullRequestReview extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The comment itself.
|
* The comment itself.
|
||||||
|
*
|
||||||
|
* @return the body
|
||||||
*/
|
*/
|
||||||
public String getBody() {
|
public String getBody() {
|
||||||
return body;
|
return body;
|
||||||
@@ -65,15 +72,29 @@ public class GHPullRequestReview extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the user who posted this review.
|
* Gets the user who posted this review.
|
||||||
|
*
|
||||||
|
* @return the user
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHUser getUser() throws IOException {
|
public GHUser getUser() throws IOException {
|
||||||
return owner.root.getUser(user.getLogin());
|
return owner.root.getUser(user.getLogin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets commit id.
|
||||||
|
*
|
||||||
|
* @return the commit id
|
||||||
|
*/
|
||||||
public String getCommitId() {
|
public String getCommitId() {
|
||||||
return commit_id;
|
return commit_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets state.
|
||||||
|
*
|
||||||
|
* @return the state
|
||||||
|
*/
|
||||||
@CheckForNull
|
@CheckForNull
|
||||||
public GHPullRequestReviewState getState() {
|
public GHPullRequestReviewState getState() {
|
||||||
return state;
|
return state;
|
||||||
@@ -84,65 +105,103 @@ public class GHPullRequestReview extends GHObject {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets api route.
|
||||||
|
*
|
||||||
|
* @return the api route
|
||||||
|
*/
|
||||||
protected String getApiRoute() {
|
protected String getApiRoute() {
|
||||||
return owner.getApiRoute()+"/reviews/"+id;
|
return owner.getApiRoute() + "/reviews/" + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* When was this resource created?
|
||||||
* Former preview method that changed when it got public. Left here for backward compatibility.
|
*
|
||||||
* Use {@link #submit(String, GHPullRequestReviewEvent)}
|
* @return the submitted at
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
|
public Date getSubmittedAt() throws IOException {
|
||||||
|
return GitHub.parseDate(submitted_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Since this method does not exist, we forward this value.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Date getCreatedAt() throws IOException {
|
||||||
|
return getSubmittedAt();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submit.
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @param state
|
||||||
|
* the state
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @deprecated Former preview method that changed when it got public. Left here for backward compatibility. Use
|
||||||
|
* {@link #submit(String, GHPullRequestReviewEvent)}
|
||||||
*/
|
*/
|
||||||
public void submit(String body, GHPullRequestReviewState state) throws IOException {
|
public void submit(String body, GHPullRequestReviewState state) throws IOException {
|
||||||
submit(body,state.toEvent());
|
submit(body, state.toEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the comment.
|
* Updates the comment.
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @param event
|
||||||
|
* the event
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void submit(String body, GHPullRequestReviewEvent event) throws IOException {
|
public void submit(String body, GHPullRequestReviewEvent event) throws IOException {
|
||||||
new Requester(owner.root).method("POST")
|
new Requester(owner.root).method("POST")
|
||||||
.with("body", body)
|
.with("body", body)
|
||||||
.with("event", event.action())
|
.with("event", event.action())
|
||||||
.to(getApiRoute()+"/events",this);
|
.to(getApiRoute() + "/events", this);
|
||||||
this.body = body;
|
this.body = body;
|
||||||
this.state = event.toState();
|
this.state = event.toState();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes this review.
|
* Deletes this review.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(owner.root).method("DELETE")
|
new Requester(owner.root).method("DELETE").to(getApiRoute());
|
||||||
.to(getApiRoute());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dismisses this review.
|
* Dismisses this review.
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
* the message
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void dismiss(String message) throws IOException {
|
public void dismiss(String message) throws IOException {
|
||||||
new Requester(owner.root).method("PUT")
|
new Requester(owner.root).method("PUT").with("message", message).to(getApiRoute() + "/dismissals");
|
||||||
.with("message", message)
|
|
||||||
.to(getApiRoute()+"/dismissals");
|
|
||||||
state = GHPullRequestReviewState.DISMISSED;
|
state = GHPullRequestReviewState.DISMISSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains all the review comments associated with this pull request review.
|
* Obtains all the review comments associated with this pull request review.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException {
|
public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException {
|
||||||
return new PagedIterable<GHPullRequestReviewComment>() {
|
return owner.root.retrieve()
|
||||||
public PagedIterator<GHPullRequestReviewComment> _iterator(int pageSize) {
|
.asPagedIterable(getApiRoute() + "/comments",
|
||||||
return new PagedIterator<GHPullRequestReviewComment>(
|
GHPullRequestReviewComment[].class,
|
||||||
owner.root.retrieve()
|
item -> item.wrapUp(owner));
|
||||||
.asIterator(getApiRoute() + "/comments",
|
|
||||||
GHPullRequestReviewComment[].class, pageSize)) {
|
|
||||||
protected void wrapUp(GHPullRequestReviewComment[] page) {
|
|
||||||
for (GHPullRequestReviewComment c : page)
|
|
||||||
c.wrapUp(owner);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,59 +8,89 @@ import java.util.List;
|
|||||||
* Builds up a creation of new {@link GHPullRequestReview}.
|
* Builds up a creation of new {@link GHPullRequestReview}.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHPullRequest#createReview()
|
* @see GHPullRequest#createReview() GHPullRequest#createReview()
|
||||||
*/
|
*/
|
||||||
public class GHPullRequestReviewBuilder {
|
public class GHPullRequestReviewBuilder {
|
||||||
private final GHPullRequest pr;
|
private final GHPullRequest pr;
|
||||||
private final Requester builder;
|
private final Requester builder;
|
||||||
private final List<DraftReviewComment> comments = new ArrayList<DraftReviewComment>();
|
private final List<DraftReviewComment> comments = new ArrayList<DraftReviewComment>();
|
||||||
|
|
||||||
/*package*/ GHPullRequestReviewBuilder(GHPullRequest pr) {
|
GHPullRequestReviewBuilder(GHPullRequest pr) {
|
||||||
this.pr = pr;
|
this.pr = pr;
|
||||||
this.builder = new Requester(pr.root);
|
this.builder = new Requester(pr.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public GHPullRequestReview createReview(@Nullable String commitId, String body, GHPullRequestReviewEvent event,
|
// public GHPullRequestReview createReview(@Nullable String commitId, String body, GHPullRequestReviewEvent event,
|
||||||
// List<GHPullRequestReviewComment> comments) throws IOException
|
// List<GHPullRequestReviewComment> comments) throws IOException
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SHA of the commit that needs a review. Not using the latest commit SHA may render your review comment outdated if a subsequent commit modifies the line you specify as the position. Defaults to the most recent commit in the pull request when you do not specify a value.
|
* The SHA of the commit that needs a review. Not using the latest commit SHA may render your review comment
|
||||||
|
* outdated if a subsequent commit modifies the line you specify as the position. Defaults to the most recent commit
|
||||||
|
* in the pull request when you do not specify a value.
|
||||||
|
*
|
||||||
|
* @param commitId
|
||||||
|
* the commit id
|
||||||
|
* @return the gh pull request review builder
|
||||||
*/
|
*/
|
||||||
public GHPullRequestReviewBuilder commitId(String commitId) {
|
public GHPullRequestReviewBuilder commitId(String commitId) {
|
||||||
builder.with("commit_id",commitId);
|
builder.with("commit_id", commitId);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required when using REQUEST_CHANGES or COMMENT for the event parameter. The body text of the pull request review.
|
* Required when using REQUEST_CHANGES or COMMENT for the event parameter. The body text of the pull request review.
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @return the gh pull request review builder
|
||||||
*/
|
*/
|
||||||
public GHPullRequestReviewBuilder body(String body) {
|
public GHPullRequestReviewBuilder body(String body) {
|
||||||
builder.with("body",body);
|
builder.with("body", body);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The review action you want to perform. The review actions include: APPROVE, REQUEST_CHANGES, or COMMENT.
|
* The review action you want to perform. The review actions include: APPROVE, REQUEST_CHANGES, or COMMENT. By
|
||||||
* By leaving this blank, you set the review action state to PENDING,
|
* leaving this blank, you set the review action state to PENDING, which means you will need to
|
||||||
* which means you will need to {@linkplain GHPullRequestReview#submit(String, GHPullRequestReviewEvent) submit the pull request review} when you are ready.
|
* {@linkplain GHPullRequestReview#submit(String, GHPullRequestReviewEvent) submit the pull request review} when you
|
||||||
|
* are ready.
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
* the event
|
||||||
|
* @return the gh pull request review builder
|
||||||
*/
|
*/
|
||||||
public GHPullRequestReviewBuilder event(GHPullRequestReviewEvent event) {
|
public GHPullRequestReviewBuilder event(GHPullRequestReviewEvent event) {
|
||||||
builder.with("event",event.action());
|
builder.with("event", event.action());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param body The relative path to the file that necessitates a review comment.
|
* Comment gh pull request review builder.
|
||||||
* @param path The position in the diff where you want to add a review comment. Note this value is not the same as the line number in the file. For help finding the position value, read the note below.
|
*
|
||||||
* @param position Text of the review comment.
|
* @param body
|
||||||
|
* The relative path to the file that necessitates a review comment.
|
||||||
|
* @param path
|
||||||
|
* The position in the diff where you want to add a review comment. Note this value is not the same as
|
||||||
|
* the line number in the file. For help finding the position value, read the note below.
|
||||||
|
* @param position
|
||||||
|
* Text of the review comment.
|
||||||
|
* @return the gh pull request review builder
|
||||||
*/
|
*/
|
||||||
public GHPullRequestReviewBuilder comment(String body, String path, int position) {
|
public GHPullRequestReviewBuilder comment(String body, String path, int position) {
|
||||||
comments.add(new DraftReviewComment(body,path,position));
|
comments.add(new DraftReviewComment(body, path, position));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create gh pull request review.
|
||||||
|
*
|
||||||
|
* @return the gh pull request review
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHPullRequestReview create() throws IOException {
|
public GHPullRequestReview create() throws IOException {
|
||||||
return builder.method("POST")._with("comments",comments)
|
return builder.method("POST")
|
||||||
|
.with("comments", comments)
|
||||||
.to(pr.getApiRoute() + "/reviews", GHPullRequestReview.class)
|
.to(pr.getApiRoute() + "/reviews", GHPullRequestReview.class)
|
||||||
.wrapUp(pr);
|
.wrapUp(pr);
|
||||||
}
|
}
|
||||||
@@ -76,14 +106,29 @@ public class GHPullRequestReviewBuilder {
|
|||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets body.
|
||||||
|
*
|
||||||
|
* @return the body
|
||||||
|
*/
|
||||||
public String getBody() {
|
public String getBody() {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets path.
|
||||||
|
*
|
||||||
|
* @return the path
|
||||||
|
*/
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets position.
|
||||||
|
*
|
||||||
|
* @return the position
|
||||||
|
*/
|
||||||
public int getPosition() {
|
public int getPosition() {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ package org.kohsuke.github;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import javax.annotation.CheckForNull;
|
import javax.annotation.CheckForNull;
|
||||||
|
|
||||||
import static org.kohsuke.github.Previews.*;
|
import static org.kohsuke.github.Previews.*;
|
||||||
@@ -33,8 +34,9 @@ import static org.kohsuke.github.Previews.*;
|
|||||||
* Review comment to the pull request
|
* Review comment to the pull request
|
||||||
*
|
*
|
||||||
* @author Julien Henry
|
* @author Julien Henry
|
||||||
* @see GHPullRequest#listReviewComments()
|
* @see GHPullRequest#listReviewComments() GHPullRequest#listReviewComments()
|
||||||
* @see GHPullRequest#createReviewComment(String, String, String, int)
|
* @see GHPullRequest#createReviewComment(String, String, String, int) GHPullRequest#createReviewComment(String, String,
|
||||||
|
* String, int)
|
||||||
*/
|
*/
|
||||||
public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
||||||
GHPullRequest owner;
|
GHPullRequest owner;
|
||||||
@@ -46,10 +48,17 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
|||||||
private int original_position = -1;
|
private int original_position = -1;
|
||||||
private long in_reply_to_id = -1L;
|
private long in_reply_to_id = -1L;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* Draft gh pull request review comment.
|
||||||
* You should be using {@link GHPullRequestReviewBuilder#comment(String, String, int)}
|
*
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @param path
|
||||||
|
* the path
|
||||||
|
* @param position
|
||||||
|
* the position
|
||||||
|
* @return the gh pull request review comment
|
||||||
|
* @deprecated You should be using {@link GHPullRequestReviewBuilder#comment(String, String, int)}
|
||||||
*/
|
*/
|
||||||
public static GHPullRequestReviewComment draft(String body, String path, int position) {
|
public static GHPullRequestReviewComment draft(String body, String path, int position) {
|
||||||
GHPullRequestReviewComment result = new GHPullRequestReviewComment();
|
GHPullRequestReviewComment result = new GHPullRequestReviewComment();
|
||||||
@@ -59,13 +68,15 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHPullRequestReviewComment wrapUp(GHPullRequest owner) {
|
GHPullRequestReviewComment wrapUp(GHPullRequest owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the pull request to which this review comment is associated.
|
* Gets the pull request to which this review comment is associated.
|
||||||
|
*
|
||||||
|
* @return the parent
|
||||||
*/
|
*/
|
||||||
public GHPullRequest getParent() {
|
public GHPullRequest getParent() {
|
||||||
return owner;
|
return owner;
|
||||||
@@ -73,6 +84,8 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The comment itself.
|
* The comment itself.
|
||||||
|
*
|
||||||
|
* @return the body
|
||||||
*/
|
*/
|
||||||
public String getBody() {
|
public String getBody() {
|
||||||
return body;
|
return body;
|
||||||
@@ -80,24 +93,48 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the user who posted this comment.
|
* Gets the user who posted this comment.
|
||||||
|
*
|
||||||
|
* @return the user
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHUser getUser() throws IOException {
|
public GHUser getUser() throws IOException {
|
||||||
return owner.root.getUser(user.getLogin());
|
return owner.root.getUser(user.getLogin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets path.
|
||||||
|
*
|
||||||
|
* @return the path
|
||||||
|
*/
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets position.
|
||||||
|
*
|
||||||
|
* @return the position
|
||||||
|
*/
|
||||||
@CheckForNull
|
@CheckForNull
|
||||||
public int getPosition() {
|
public int getPosition() {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets original position.
|
||||||
|
*
|
||||||
|
* @return the original position
|
||||||
|
*/
|
||||||
public int getOriginalPosition() {
|
public int getOriginalPosition() {
|
||||||
return original_position;
|
return original_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets in reply to id.
|
||||||
|
*
|
||||||
|
* @return the in reply to id
|
||||||
|
*/
|
||||||
@CheckForNull
|
@CheckForNull
|
||||||
public long getInReplyToId() {
|
public long getInReplyToId() {
|
||||||
return in_reply_to_id;
|
return in_reply_to_id;
|
||||||
@@ -108,20 +145,33 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets api route.
|
||||||
|
*
|
||||||
|
* @return the api route
|
||||||
|
*/
|
||||||
protected String getApiRoute() {
|
protected String getApiRoute() {
|
||||||
return "/repos/"+owner.getRepository().getFullName()+"/pulls/comments/"+id;
|
return "/repos/" + owner.getRepository().getFullName() + "/pulls/comments/" + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the comment.
|
* Updates the comment.
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void update(String body) throws IOException {
|
public void update(String body) throws IOException {
|
||||||
new Requester(owner.root).method("PATCH").with("body", body).to(getApiRoute(),this);
|
new Requester(owner.root).method("PATCH").with("body", body).to(getApiRoute(), this);
|
||||||
this.body = body;
|
this.body = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes this review comment.
|
* Deletes this review comment.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(owner.root).method("DELETE").to(getApiRoute());
|
new Requester(owner.root).method("DELETE").to(getApiRoute());
|
||||||
@@ -129,6 +179,12 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new comment that replies to this comment.
|
* Create a new comment that replies to this comment.
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* the body
|
||||||
|
* @return the gh pull request review comment
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public GHPullRequestReviewComment reply(String body) throws IOException {
|
public GHPullRequestReviewComment reply(String body) throws IOException {
|
||||||
return new Requester(owner.root).method("POST")
|
return new Requester(owner.root).method("POST")
|
||||||
@@ -138,26 +194,20 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable {
|
|||||||
.wrapUp(owner);
|
.wrapUp(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview @Deprecated
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public GHReaction createReaction(ReactionContent content) throws IOException {
|
public GHReaction createReaction(ReactionContent content) throws IOException {
|
||||||
return new Requester(owner.root)
|
return new Requester(owner.root).withPreview(SQUIRREL_GIRL)
|
||||||
.withPreview(SQUIRREL_GIRL)
|
|
||||||
.with("content", content.getContent())
|
.with("content", content.getContent())
|
||||||
.to(getApiRoute()+"/reactions", GHReaction.class).wrap(owner.root);
|
.to(getApiRoute() + "/reactions", GHReaction.class)
|
||||||
|
.wrap(owner.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview @Deprecated
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public PagedIterable<GHReaction> listReactions() {
|
public PagedIterable<GHReaction> listReactions() {
|
||||||
return new PagedIterable<GHReaction>() {
|
return owner.root.retrieve()
|
||||||
public PagedIterator<GHReaction> _iterator(int pageSize) {
|
.withPreview(SQUIRREL_GIRL)
|
||||||
return new PagedIterator<GHReaction>(owner.root.retrieve().withPreview(SQUIRREL_GIRL).asIterator(getApiRoute() + "/reactions", GHReaction[].class, pageSize)) {
|
.asPagedIterable(getApiRoute() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root));
|
||||||
@Override
|
|
||||||
protected void wrapUp(GHReaction[] page) {
|
|
||||||
for (GHReaction c : page)
|
|
||||||
c.wrap(owner.root);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,24 +27,25 @@ package org.kohsuke.github;
|
|||||||
* Action to perform on {@link GHPullRequestReview}.
|
* Action to perform on {@link GHPullRequestReview}.
|
||||||
*/
|
*/
|
||||||
public enum GHPullRequestReviewEvent {
|
public enum GHPullRequestReviewEvent {
|
||||||
PENDING,
|
PENDING, APPROVE, REQUEST_CHANGES, COMMENT;
|
||||||
APPROVE,
|
|
||||||
REQUEST_CHANGES,
|
|
||||||
COMMENT;
|
|
||||||
|
|
||||||
/*package*/ String action() {
|
String action() {
|
||||||
return this==PENDING ? null : name();
|
return this == PENDING ? null : name();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When a {@link GHPullRequestReview} is submitted with this event, it should transition to this state.
|
* When a {@link GHPullRequestReview} is submitted with this event, it should transition to this state.
|
||||||
*/
|
*/
|
||||||
/*package*/ GHPullRequestReviewState toState() {
|
GHPullRequestReviewState toState() {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case PENDING: return GHPullRequestReviewState.PENDING;
|
case PENDING :
|
||||||
case APPROVE: return GHPullRequestReviewState.APPROVED;
|
return GHPullRequestReviewState.PENDING;
|
||||||
case REQUEST_CHANGES: return GHPullRequestReviewState.CHANGES_REQUESTED;
|
case APPROVE :
|
||||||
case COMMENT: return GHPullRequestReviewState.COMMENTED;
|
return GHPullRequestReviewState.APPROVED;
|
||||||
|
case REQUEST_CHANGES :
|
||||||
|
return GHPullRequestReviewState.CHANGES_REQUESTED;
|
||||||
|
case COMMENT :
|
||||||
|
return GHPullRequestReviewState.COMMENTED;
|
||||||
}
|
}
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,31 +8,36 @@ public enum GHPullRequestReviewState {
|
|||||||
APPROVED,
|
APPROVED,
|
||||||
CHANGES_REQUESTED,
|
CHANGES_REQUESTED,
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated This was the thing when this API was in preview, but it changed when it became public. Use
|
||||||
* This was the thing when this API was in preview, but it changed when it became public.
|
* {@link #CHANGES_REQUESTED}. Left here for compatibility.
|
||||||
* Use {@link #CHANGES_REQUESTED}. Left here for compatibility.
|
|
||||||
*/
|
*/
|
||||||
REQUEST_CHANGES,
|
REQUEST_CHANGES,
|
||||||
COMMENTED,
|
COMMENTED,
|
||||||
DISMISSED;
|
DISMISSED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* Action string.
|
||||||
* This was an internal method accidentally exposed.
|
*
|
||||||
* Left here for compatibility.
|
* @return the string
|
||||||
|
* @deprecated This was an internal method accidentally exposed. Left here for compatibility.
|
||||||
*/
|
*/
|
||||||
public String action() {
|
public String action() {
|
||||||
GHPullRequestReviewEvent e = toEvent();
|
GHPullRequestReviewEvent e = toEvent();
|
||||||
return e==null ? null : e.action();
|
return e == null ? null : e.action();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHPullRequestReviewEvent toEvent() {
|
GHPullRequestReviewEvent toEvent() {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case PENDING: return GHPullRequestReviewEvent.PENDING;
|
case PENDING :
|
||||||
case APPROVED: return GHPullRequestReviewEvent.APPROVE;
|
return GHPullRequestReviewEvent.PENDING;
|
||||||
case CHANGES_REQUESTED: return GHPullRequestReviewEvent.REQUEST_CHANGES;
|
case APPROVED :
|
||||||
case REQUEST_CHANGES: return GHPullRequestReviewEvent.REQUEST_CHANGES;
|
return GHPullRequestReviewEvent.APPROVE;
|
||||||
case COMMENTED: return GHPullRequestReviewEvent.COMMENT;
|
case CHANGES_REQUESTED :
|
||||||
|
return GHPullRequestReviewEvent.REQUEST_CHANGES;
|
||||||
|
case REQUEST_CHANGES :
|
||||||
|
return GHPullRequestReviewEvent.REQUEST_CHANGES;
|
||||||
|
case COMMENTED :
|
||||||
|
return GHPullRequestReviewEvent.COMMENT;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,19 +3,23 @@ package org.kohsuke.github;
|
|||||||
/**
|
/**
|
||||||
* Used to specify filters, sort order, etc for listing items in a collection.
|
* Used to specify filters, sort order, etc for listing items in a collection.
|
||||||
*
|
*
|
||||||
|
* @param <T>
|
||||||
|
* the type parameter
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public abstract class GHQueryBuilder<T> {
|
public abstract class GHQueryBuilder<T> {
|
||||||
protected final GitHub root;
|
protected final GitHub root;
|
||||||
protected final Requester req;
|
protected final Requester req;
|
||||||
|
|
||||||
/*package*/ GHQueryBuilder(GitHub root) {
|
GHQueryBuilder(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
this.req = root.retrieve();
|
this.req = root.retrieve();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start listing items by using the settings built up on this object.
|
* Start listing items by using the settings built up on this object.
|
||||||
|
*
|
||||||
|
* @return the paged iterable
|
||||||
*/
|
*/
|
||||||
public abstract PagedIterable<T> list();
|
public abstract PagedIterable<T> list();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +1,400 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.format.DateTimeParseException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.FINEST;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rate limit.
|
* Rate limit.
|
||||||
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
|
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", justification = "JSON API")
|
||||||
public class GHRateLimit {
|
public class GHRateLimit {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remaining calls that can be made.
|
* Remaining calls that can be made.
|
||||||
|
*
|
||||||
|
* @deprecated This value should never have been made public. Use {@link #getRemaining()}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public int remaining;
|
public int remaining;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allotted API call per hour.
|
* Allotted API call per hour.
|
||||||
|
*
|
||||||
|
* @deprecated This value should never have been made public. Use {@link #getLimit()}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public int limit;
|
public int limit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time at which the current rate limit window resets in UTC epoch seconds.
|
* The time at which the current rate limit window resets in UTC epoch seconds. NOTE: that means to
|
||||||
|
*
|
||||||
|
* @deprecated This value should never have been made public. Use {@link #getResetDate()}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Date reset;
|
public Date reset;
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private final Record core;
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private final Record search;
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private final Record graphql;
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private final Record integrationManifest;
|
||||||
|
|
||||||
|
static GHRateLimit Unknown() {
|
||||||
|
return new GHRateLimit(new UnknownLimitRecord(),
|
||||||
|
new UnknownLimitRecord(),
|
||||||
|
new UnknownLimitRecord(),
|
||||||
|
new UnknownLimitRecord());
|
||||||
|
}
|
||||||
|
|
||||||
|
static GHRateLimit fromHeaderRecord(Record header) {
|
||||||
|
return new GHRateLimit(header, new UnknownLimitRecord(), new UnknownLimitRecord(), new UnknownLimitRecord());
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
GHRateLimit(@Nonnull @JsonProperty("core") Record core,
|
||||||
|
@Nonnull @JsonProperty("search") Record search,
|
||||||
|
@Nonnull @JsonProperty("graphql") Record graphql,
|
||||||
|
@Nonnull @JsonProperty("integration_manifest") Record integrationManifest) {
|
||||||
|
this.core = core;
|
||||||
|
this.search = search;
|
||||||
|
this.graphql = graphql;
|
||||||
|
this.integrationManifest = integrationManifest;
|
||||||
|
|
||||||
|
// Deprecated fields
|
||||||
|
this.remaining = core.getRemaining();
|
||||||
|
this.limit = core.getLimit();
|
||||||
|
this.reset = new Date(core.getResetEpochSeconds());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-epoch date
|
* Returns the date at which the Core API rate limit will reset.
|
||||||
|
*
|
||||||
|
* @return the calculated date at which the rate limit has or will reset.
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR",
|
@Nonnull
|
||||||
justification = "The value comes from JSON deserialization")
|
|
||||||
public Date getResetDate() {
|
public Date getResetDate() {
|
||||||
return new Date(reset.getTime() * 1000);
|
return getCore().getResetDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the remaining number of Core APIs requests allowed before this connection will be throttled.
|
||||||
|
*
|
||||||
|
* @return an integer
|
||||||
|
* @since 1.100
|
||||||
|
*/
|
||||||
|
public int getRemaining() {
|
||||||
|
return getCore().getRemaining();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the total number of Core API calls per hour allotted for this connection.
|
||||||
|
*
|
||||||
|
* @return an integer
|
||||||
|
* @since 1.100
|
||||||
|
*/
|
||||||
|
public int getLimit() {
|
||||||
|
return getCore().getLimit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the time in epoch seconds when the Core API rate limit will reset.
|
||||||
|
*
|
||||||
|
* @return a long
|
||||||
|
* @since 1.100
|
||||||
|
*/
|
||||||
|
public long getResetEpochSeconds() {
|
||||||
|
return getCore().getResetEpochSeconds();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the rate limit reset date for this instance has passed.
|
||||||
|
*
|
||||||
|
* @return true if the rate limit reset date has passed. Otherwise false.
|
||||||
|
* @since 1.100
|
||||||
|
*/
|
||||||
|
public boolean isExpired() {
|
||||||
|
return getCore().isExpired();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The core object provides your rate limit status for all non-search-related resources in the REST API.
|
||||||
|
*
|
||||||
|
* @return a rate limit record
|
||||||
|
* @since 1.100
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public Record getCore() {
|
||||||
|
return core;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The search object provides your rate limit status for the Search API. TODO: integrate with header limit updating.
|
||||||
|
* Issue #605.
|
||||||
|
*
|
||||||
|
* @return a rate limit record
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
Record getSearch() {
|
||||||
|
return search;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The graphql object provides your rate limit status for the GraphQL API. TODO: integrate with header limit
|
||||||
|
* updating. Issue #605.
|
||||||
|
*
|
||||||
|
* @return a rate limit record
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
Record getGraphQL() {
|
||||||
|
return graphql;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The integration_manifest object provides your rate limit status for the GitHub App Manifest code conversion
|
||||||
|
* endpoint. TODO: integrate with header limit updating. Issue #605.
|
||||||
|
*
|
||||||
|
* @return a rate limit record
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
Record getIntegrationManifest() {
|
||||||
|
return integrationManifest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "GHRateLimit{" +
|
return "GHRateLimit {" + "core " + getCore().toString() + "search " + getSearch().toString() + "graphql "
|
||||||
"remaining=" + remaining +
|
+ getGraphQL().toString() + "integrationManifest " + getIntegrationManifest().toString() + '}';
|
||||||
", limit=" + limit +
|
|
||||||
", resetDate=" + getResetDate() +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
GHRateLimit rateLimit = (GHRateLimit) o;
|
||||||
|
return getCore().equals(rateLimit.getCore()) && getSearch().equals(rateLimit.getSearch())
|
||||||
|
&& getGraphQL().equals(rateLimit.getGraphQL())
|
||||||
|
&& getIntegrationManifest().equals(rateLimit.getIntegrationManifest());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(getCore(), getSearch(), getGraphQL(), getIntegrationManifest());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A limit record used as a placeholder when the the actual limit is not known.
|
||||||
|
* <p>
|
||||||
|
* Has a large limit and long duration so that it will doesn't expire too often.
|
||||||
|
*
|
||||||
|
* @since 1.100
|
||||||
|
*/
|
||||||
|
public static class UnknownLimitRecord extends Record {
|
||||||
|
|
||||||
|
// One hour
|
||||||
|
private static final long unknownLimitResetSeconds = 60L * 60L;
|
||||||
|
|
||||||
|
static final int unknownLimit = 1000000;
|
||||||
|
static final int unknownRemaining = 999999;
|
||||||
|
|
||||||
|
private UnknownLimitRecord() {
|
||||||
|
super(unknownLimit, unknownRemaining, System.currentTimeMillis() / 1000L + unknownLimitResetSeconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A rate limit record.
|
||||||
|
*
|
||||||
|
* @since 1.100
|
||||||
|
*/
|
||||||
|
public static class Record {
|
||||||
|
/**
|
||||||
|
* Remaining calls that can be made.
|
||||||
|
*/
|
||||||
|
private final int remaining;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allotted API call per hour.
|
||||||
|
*/
|
||||||
|
private final int limit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time at which the current rate limit window resets in UTC epoch seconds.
|
||||||
|
*/
|
||||||
|
private final long resetEpochSeconds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EpochSeconds time (UTC) at which this instance was created.
|
||||||
|
*/
|
||||||
|
private final long createdAtEpochSeconds = System.currentTimeMillis() / 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The calculated time at which the rate limit will reset. Recalculated if {@link #recalculateResetDate} is
|
||||||
|
* called.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
private Date resetDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Record.
|
||||||
|
*
|
||||||
|
* @param limit
|
||||||
|
* the limit
|
||||||
|
* @param remaining
|
||||||
|
* the remaining
|
||||||
|
* @param resetEpochSeconds
|
||||||
|
* the reset epoch seconds
|
||||||
|
*/
|
||||||
|
@JsonCreator
|
||||||
|
public Record(@JsonProperty("limit") int limit,
|
||||||
|
@JsonProperty("remaining") int remaining,
|
||||||
|
@JsonProperty("reset") long resetEpochSeconds) {
|
||||||
|
this(limit, remaining, resetEpochSeconds, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Record.
|
||||||
|
*
|
||||||
|
* @param limit
|
||||||
|
* the limit
|
||||||
|
* @param remaining
|
||||||
|
* the remaining
|
||||||
|
* @param resetEpochSeconds
|
||||||
|
* the reset epoch seconds
|
||||||
|
* @param updatedAt
|
||||||
|
* the updated at
|
||||||
|
*/
|
||||||
|
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", justification = "Deprecated")
|
||||||
|
public Record(int limit, int remaining, long resetEpochSeconds, String updatedAt) {
|
||||||
|
this.limit = limit;
|
||||||
|
this.remaining = remaining;
|
||||||
|
this.resetEpochSeconds = resetEpochSeconds;
|
||||||
|
this.resetDate = recalculateResetDate(updatedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recalculates the reset date using the server response date to calculate a time duration and then add that to
|
||||||
|
* the local created time for this record.
|
||||||
|
*
|
||||||
|
* @param updatedAt
|
||||||
|
* a string date in RFC 1123
|
||||||
|
* @return reset date based on the passed date
|
||||||
|
*/
|
||||||
|
Date recalculateResetDate(String updatedAt) {
|
||||||
|
long updatedAtEpochSeconds = createdAtEpochSeconds;
|
||||||
|
if (!StringUtils.isBlank(updatedAt)) {
|
||||||
|
try {
|
||||||
|
// Get the server date and reset data, will always return a time in GMT
|
||||||
|
updatedAtEpochSeconds = ZonedDateTime.parse(updatedAt, DateTimeFormatter.RFC_1123_DATE_TIME)
|
||||||
|
.toEpochSecond();
|
||||||
|
} catch (DateTimeParseException e) {
|
||||||
|
if (LOGGER.isLoggable(FINEST)) {
|
||||||
|
LOGGER.log(FINEST, "Malformed Date header value " + updatedAt, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This may seem odd but it results in an accurate or slightly pessimistic reset date
|
||||||
|
// based on system time rather than on the system being in sync with the server
|
||||||
|
long calculatedSecondsUntilReset = resetEpochSeconds - updatedAtEpochSeconds;
|
||||||
|
return resetDate = new Date((createdAtEpochSeconds + calculatedSecondsUntilReset) * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the remaining number of requests allowed before this connection will be throttled.
|
||||||
|
*
|
||||||
|
* @return an integer
|
||||||
|
*/
|
||||||
|
public int getRemaining() {
|
||||||
|
return remaining;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the total number of API calls per hour allotted for this connection.
|
||||||
|
*
|
||||||
|
* @return an integer
|
||||||
|
*/
|
||||||
|
public int getLimit() {
|
||||||
|
return limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the time in epoch seconds when the rate limit will reset.
|
||||||
|
*
|
||||||
|
* @return a long
|
||||||
|
*/
|
||||||
|
public long getResetEpochSeconds() {
|
||||||
|
return resetEpochSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the rate limit reset date indicated by this instance is in the
|
||||||
|
*
|
||||||
|
* @return true if the rate limit reset date has passed. Otherwise false.
|
||||||
|
*/
|
||||||
|
public boolean isExpired() {
|
||||||
|
return getResetDate().getTime() < System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the date at which the rate limit will reset.
|
||||||
|
*
|
||||||
|
* @return the calculated date at which the rate limit has or will reset.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public Date getResetDate() {
|
||||||
|
return new Date(resetDate.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{" + "remaining=" + getRemaining() + ", limit=" + getLimit() + ", resetDate=" + getResetDate()
|
||||||
|
+ '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Record record = (Record) o;
|
||||||
|
return getRemaining() == record.getRemaining() && getLimit() == record.getLimit()
|
||||||
|
&& getResetEpochSeconds() == record.getResetEpochSeconds()
|
||||||
|
&& getResetDate().equals(record.getResetDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(getRemaining(), getLimit(), getResetEpochSeconds(), getResetDate());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(Requester.class.getName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,14 +11,15 @@ import static org.kohsuke.github.Previews.*;
|
|||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see Reactable
|
* @see Reactable
|
||||||
*/
|
*/
|
||||||
@Preview @Deprecated
|
@Preview
|
||||||
|
@Deprecated
|
||||||
public class GHReaction extends GHObject {
|
public class GHReaction extends GHObject {
|
||||||
private GitHub root;
|
private GitHub root;
|
||||||
|
|
||||||
private GHUser user;
|
private GHUser user;
|
||||||
private ReactionContent content;
|
private ReactionContent content;
|
||||||
|
|
||||||
/*package*/ GHReaction wrap(GitHub root) {
|
GHReaction wrap(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
user.wrapUp(root);
|
user.wrapUp(root);
|
||||||
return this;
|
return this;
|
||||||
@@ -26,6 +27,8 @@ public class GHReaction extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The kind of reaction left.
|
* The kind of reaction left.
|
||||||
|
*
|
||||||
|
* @return the content
|
||||||
*/
|
*/
|
||||||
public ReactionContent getContent() {
|
public ReactionContent getContent() {
|
||||||
return content;
|
return content;
|
||||||
@@ -33,6 +36,8 @@ public class GHReaction extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* User who left the reaction.
|
* User who left the reaction.
|
||||||
|
*
|
||||||
|
* @return the user
|
||||||
*/
|
*/
|
||||||
public GHUser getUser() {
|
public GHUser getUser() {
|
||||||
return user;
|
return user;
|
||||||
@@ -48,8 +53,11 @@ public class GHReaction extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes this reaction.
|
* Removes this reaction.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(root).method("DELETE").withPreview(SQUIRREL_GIRL).to("/reactions/"+id);
|
new Requester(root).method("DELETE").withPreview(SQUIRREL_GIRL).to("/reactions/" + id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,15 @@ import java.net.URL;
|
|||||||
* @author Michael Clarke
|
* @author Michael Clarke
|
||||||
*/
|
*/
|
||||||
public class GHRef {
|
public class GHRef {
|
||||||
/*package almost final*/ GitHub root;
|
/* package almost final */ GitHub root;
|
||||||
|
|
||||||
private String ref, url;
|
private String ref, url;
|
||||||
private GHObject object;
|
private GHObject object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the ref, such as "refs/tags/abc"
|
* Name of the ref, such as "refs/tags/abc"
|
||||||
|
*
|
||||||
|
* @return the ref
|
||||||
*/
|
*/
|
||||||
public String getRef() {
|
public String getRef() {
|
||||||
return ref;
|
return ref;
|
||||||
@@ -25,6 +27,8 @@ public class GHRef {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The API URL of this tag, such as https://api.github.com/repos/jenkinsci/jenkins/git/refs/tags/1.312
|
* The API URL of this tag, such as https://api.github.com/repos/jenkinsci/jenkins/git/refs/tags/1.312
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
*/
|
*/
|
||||||
public URL getUrl() {
|
public URL getUrl() {
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
@@ -32,6 +36,8 @@ public class GHRef {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The object that this ref points to.
|
* The object that this ref points to.
|
||||||
|
*
|
||||||
|
* @return the object
|
||||||
*/
|
*/
|
||||||
public GHObject getObject() {
|
public GHObject getObject() {
|
||||||
return object;
|
return object;
|
||||||
@@ -41,51 +47,63 @@ public class GHRef {
|
|||||||
* Updates this ref to the specified commit.
|
* Updates this ref to the specified commit.
|
||||||
*
|
*
|
||||||
* @param sha
|
* @param sha
|
||||||
* The SHA1 value to set this reference to
|
* The SHA1 value to set this reference to
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void updateTo(String sha) throws IOException {
|
public void updateTo(String sha) throws IOException {
|
||||||
updateTo(sha, false);
|
updateTo(sha, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates this ref to the specified commit.
|
* Updates this ref to the specified commit.
|
||||||
*
|
*
|
||||||
* @param sha
|
* @param sha
|
||||||
* The SHA1 value to set this reference to
|
* The SHA1 value to set this reference to
|
||||||
* @param force
|
* @param force
|
||||||
* Whether or not to force this ref update.
|
* Whether or not to force this ref update.
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void updateTo(String sha, Boolean force) throws IOException {
|
public void updateTo(String sha, Boolean force) throws IOException {
|
||||||
new Requester(root)
|
new Requester(root).with("sha", sha).with("force", force).method("PATCH").to(url, GHRef.class).wrap(root);
|
||||||
.with("sha", sha).with("force", force).method("PATCH").to(url, GHRef.class).wrap(root);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes this ref from the repository using the GitHub API.
|
* Deletes this ref from the repository using the GitHub API.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(root).method("DELETE").to(url);
|
new Requester(root).method("DELETE").to(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHRef wrap(GitHub root) {
|
GHRef wrap(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ static GHRef[] wrap(GHRef[] in, GitHub root) {
|
static GHRef[] wrap(GHRef[] in, GitHub root) {
|
||||||
for (GHRef r : in) {
|
for (GHRef r : in) {
|
||||||
r.wrap(root);
|
r.wrap(root);
|
||||||
}
|
}
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
|
/**
|
||||||
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
|
* The type GHObject.
|
||||||
|
*/
|
||||||
|
@SuppressFBWarnings(
|
||||||
|
value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
|
||||||
|
justification = "JSON API")
|
||||||
public static class GHObject {
|
public static class GHObject {
|
||||||
private String type, sha, url;
|
private String type, sha, url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of the object, such as "commit"
|
* Type of the object, such as "commit"
|
||||||
|
*
|
||||||
|
* @return the type
|
||||||
*/
|
*/
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
@@ -93,13 +111,18 @@ public class GHRef {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* SHA1 of this object.
|
* SHA1 of this object.
|
||||||
|
*
|
||||||
|
* @return the sha
|
||||||
*/
|
*/
|
||||||
public String getSha() {
|
public String getSha() {
|
||||||
return sha;
|
return sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API URL to this Git data, such as https://api.github.com/repos/jenkinsci/jenkins/git/commits/b72322675eb0114363a9a86e9ad5a170d1d07ac0
|
* API URL to this Git data, such as
|
||||||
|
* https://api.github.com/repos/jenkinsci/jenkins/git/commits/b72322675eb0114363a9a86e9ad5a170d1d07ac0
|
||||||
|
*
|
||||||
|
* @return the url
|
||||||
*/
|
*/
|
||||||
public URL getUrl() {
|
public URL getUrl() {
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -14,8 +15,8 @@ import static java.lang.String.*;
|
|||||||
/**
|
/**
|
||||||
* Release in a github repository.
|
* Release in a github repository.
|
||||||
*
|
*
|
||||||
* @see GHRepository#getReleases()
|
* @see GHRepository#getReleases() GHRepository#getReleases()
|
||||||
* @see GHRepository#createRelease(String)
|
* @see GHRepository#createRelease(String) GHRepository#createRelease(String)
|
||||||
*/
|
*/
|
||||||
public class GHRelease extends GHObject {
|
public class GHRelease extends GHObject {
|
||||||
GitHub root;
|
GitHub root;
|
||||||
@@ -34,21 +35,42 @@ public class GHRelease extends GHObject {
|
|||||||
private String tarball_url;
|
private String tarball_url;
|
||||||
private String zipball_url;
|
private String zipball_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets assets url.
|
||||||
|
*
|
||||||
|
* @return the assets url
|
||||||
|
*/
|
||||||
public String getAssetsUrl() {
|
public String getAssetsUrl() {
|
||||||
return assets_url;
|
return assets_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets body.
|
||||||
|
*
|
||||||
|
* @return the body
|
||||||
|
*/
|
||||||
public String getBody() {
|
public String getBody() {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is draft boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isDraft() {
|
public boolean isDraft() {
|
||||||
return draft;
|
return draft;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* Sets draft.
|
||||||
* Use {@link #update()}
|
*
|
||||||
|
* @param draft
|
||||||
|
* the draft
|
||||||
|
* @return the draft
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
* @deprecated Use {@link #update()}
|
||||||
*/
|
*/
|
||||||
public GHRelease setDraft(boolean draft) throws IOException {
|
public GHRelease setDraft(boolean draft) throws IOException {
|
||||||
return update().draft(draft).update();
|
return update().draft(draft).update();
|
||||||
@@ -58,50 +80,112 @@ public class GHRelease extends GHObject {
|
|||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets name.
|
||||||
|
*
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets name.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name
|
||||||
|
*/
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets owner.
|
||||||
|
*
|
||||||
|
* @return the owner
|
||||||
|
*/
|
||||||
public GHRepository getOwner() {
|
public GHRepository getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets owner.
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
* the owner
|
||||||
|
*/
|
||||||
public void setOwner(GHRepository owner) {
|
public void setOwner(GHRepository owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is prerelease boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
public boolean isPrerelease() {
|
public boolean isPrerelease() {
|
||||||
return prerelease;
|
return prerelease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets published at.
|
||||||
|
*
|
||||||
|
* @return the published at
|
||||||
|
*/
|
||||||
public Date getPublished_at() {
|
public Date getPublished_at() {
|
||||||
return new Date(published_at.getTime());
|
return new Date(published_at.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets root.
|
||||||
|
*
|
||||||
|
* @return the root
|
||||||
|
*/
|
||||||
public GitHub getRoot() {
|
public GitHub getRoot() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets tag name.
|
||||||
|
*
|
||||||
|
* @return the tag name
|
||||||
|
*/
|
||||||
public String getTagName() {
|
public String getTagName() {
|
||||||
return tag_name;
|
return tag_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets target commitish.
|
||||||
|
*
|
||||||
|
* @return the target commitish
|
||||||
|
*/
|
||||||
public String getTargetCommitish() {
|
public String getTargetCommitish() {
|
||||||
return target_commitish;
|
return target_commitish;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets upload url.
|
||||||
|
*
|
||||||
|
* @return the upload url
|
||||||
|
*/
|
||||||
public String getUploadUrl() {
|
public String getUploadUrl() {
|
||||||
return upload_url;
|
return upload_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets zipball url.
|
||||||
|
*
|
||||||
|
* @return the zipball url
|
||||||
|
*/
|
||||||
public String getZipballUrl() {
|
public String getZipballUrl() {
|
||||||
return zipball_url;
|
return zipball_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets tarball url.
|
||||||
|
*
|
||||||
|
* @return the tarball url
|
||||||
|
*/
|
||||||
public String getTarballUrl() {
|
public String getTarballUrl() {
|
||||||
return tarball_url;
|
return tarball_url;
|
||||||
}
|
}
|
||||||
@@ -121,10 +205,18 @@ public class GHRelease extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Because github relies on SNI (http://en.wikipedia.org/wiki/Server_Name_Indication) this method will only work on
|
* Because github relies on SNI (http://en.wikipedia.org/wiki/Server_Name_Indication) this method will only work on
|
||||||
* Java 7 or greater. Options for fixing this for earlier JVMs can be found here
|
* Java 7 or greater. Options for fixing this for earlier JVMs can be found here
|
||||||
* http://stackoverflow.com/questions/12361090/server-name-indication-sni-on-java but involve more complicated
|
* http://stackoverflow.com/questions/12361090/server-name-indication-sni-on-java but involve more complicated
|
||||||
* handling of the HTTP requests to github's API.
|
* handling of the HTTP requests to github's API.
|
||||||
*/
|
*
|
||||||
|
* @param file
|
||||||
|
* the file
|
||||||
|
* @param contentType
|
||||||
|
* the content type
|
||||||
|
* @return the gh asset
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHAsset uploadAsset(File file, String contentType) throws IOException {
|
public GHAsset uploadAsset(File file, String contentType) throws IOException {
|
||||||
FileInputStream s = new FileInputStream(file);
|
FileInputStream s = new FileInputStream(file);
|
||||||
try {
|
try {
|
||||||
@@ -133,41 +225,63 @@ public class GHRelease extends GHObject {
|
|||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload asset gh asset.
|
||||||
|
*
|
||||||
|
* @param filename
|
||||||
|
* the filename
|
||||||
|
* @param stream
|
||||||
|
* the stream
|
||||||
|
* @param contentType
|
||||||
|
* the content type
|
||||||
|
* @return the gh asset
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHAsset uploadAsset(String filename, InputStream stream, String contentType) throws IOException {
|
public GHAsset uploadAsset(String filename, InputStream stream, String contentType) throws IOException {
|
||||||
Requester builder = new Requester(owner.root);
|
Requester builder = new Requester(owner.root);
|
||||||
|
String url = getUploadUrl();
|
||||||
String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s",
|
// strip the helpful garbage from the url
|
||||||
owner.getApiTailUrl(""), getId(), filename);
|
url = url.substring(0, url.indexOf('{'));
|
||||||
return builder.contentType(contentType)
|
url += "?name=" + URLEncoder.encode(filename, "UTF-8");
|
||||||
.with(stream)
|
return builder.contentType(contentType).with(stream).to(url, GHAsset.class).wrap(this);
|
||||||
.to(url, GHAsset.class).wrap(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets assets.
|
||||||
|
*
|
||||||
|
* @return the assets
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public List<GHAsset> getAssets() throws IOException {
|
public List<GHAsset> getAssets() throws IOException {
|
||||||
Requester builder = new Requester(owner.root);
|
Requester builder = new Requester(owner.root);
|
||||||
|
|
||||||
GHAsset[] assets = builder
|
GHAsset[] assets = builder.method("GET").to(getApiTailUrl("assets"), GHAsset[].class);
|
||||||
.method("GET")
|
|
||||||
.to(getApiTailUrl("assets"), GHAsset[].class);
|
|
||||||
return Arrays.asList(GHAsset.wrap(assets, this));
|
return Arrays.asList(GHAsset.wrap(assets, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes this release.
|
* Deletes this release.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(root).method("DELETE").to(owner.getApiTailUrl("releases/"+id));
|
new Requester(root).method("DELETE").to(owner.getApiTailUrl("releases/" + id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates this release via a builder.
|
* Updates this release via a builder.
|
||||||
|
*
|
||||||
|
* @return the gh release updater
|
||||||
*/
|
*/
|
||||||
public GHReleaseUpdater update() {
|
public GHReleaseUpdater update() {
|
||||||
return new GHReleaseUpdater(this);
|
return new GHReleaseUpdater(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getApiTailUrl(String end) {
|
private String getApiTailUrl(String end) {
|
||||||
return owner.getApiTailUrl(format("releases/%s/%s",id,end));
|
return owner.getApiTailUrl(format("releases/%s/%s", id, end));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,20 @@ import java.io.IOException;
|
|||||||
/**
|
/**
|
||||||
* Builder pattern for creating a {@link GHRelease}
|
* Builder pattern for creating a {@link GHRelease}
|
||||||
*
|
*
|
||||||
* @see GHRepository#createRelease(String)
|
* @see GHRepository#createRelease(String) GHRepository#createRelease(String)
|
||||||
*/
|
*/
|
||||||
public class GHReleaseBuilder {
|
public class GHReleaseBuilder {
|
||||||
private final GHRepository repo;
|
private final GHRepository repo;
|
||||||
private final Requester builder;
|
private final Requester builder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Gh release builder.
|
||||||
|
*
|
||||||
|
* @param ghRepository
|
||||||
|
* the gh repository
|
||||||
|
* @param tag
|
||||||
|
* the tag
|
||||||
|
*/
|
||||||
public GHReleaseBuilder(GHRepository ghRepository, String tag) {
|
public GHReleaseBuilder(GHRepository ghRepository, String tag) {
|
||||||
this.repo = ghRepository;
|
this.repo = ghRepository;
|
||||||
this.builder = new Requester(repo.root);
|
this.builder = new Requester(repo.root);
|
||||||
@@ -18,7 +26,11 @@ public class GHReleaseBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param body The release notes body.
|
* Body gh release builder.
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* The release notes body.
|
||||||
|
* @return the gh release builder
|
||||||
*/
|
*/
|
||||||
public GHReleaseBuilder body(String body) {
|
public GHReleaseBuilder body(String body) {
|
||||||
builder.with("body", body);
|
builder.with("body", body);
|
||||||
@@ -26,11 +38,11 @@ public class GHReleaseBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the commitish value that determines where the Git tag is created from. Can be any branch or
|
* Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA.
|
||||||
* commit SHA.
|
|
||||||
*
|
*
|
||||||
* @param commitish Defaults to the repository’s default branch (usually "master"). Unused if the Git tag
|
* @param commitish
|
||||||
* already exists.
|
* Defaults to the repository’s default branch (usually "master"). Unused if the Git tag already exists.
|
||||||
|
* @return the gh release builder
|
||||||
*/
|
*/
|
||||||
public GHReleaseBuilder commitish(String commitish) {
|
public GHReleaseBuilder commitish(String commitish) {
|
||||||
builder.with("target_commitish", commitish);
|
builder.with("target_commitish", commitish);
|
||||||
@@ -40,8 +52,10 @@ public class GHReleaseBuilder {
|
|||||||
/**
|
/**
|
||||||
* Optional.
|
* Optional.
|
||||||
*
|
*
|
||||||
* @param draft {@code true} to create a draft (unpublished) release, {@code false} to create a published one.
|
* @param draft
|
||||||
* Default is {@code false}.
|
* {@code true} to create a draft (unpublished) release, {@code false} to create a published one. Default
|
||||||
|
* is {@code false}.
|
||||||
|
* @return the gh release builder
|
||||||
*/
|
*/
|
||||||
public GHReleaseBuilder draft(boolean draft) {
|
public GHReleaseBuilder draft(boolean draft) {
|
||||||
builder.with("draft", draft);
|
builder.with("draft", draft);
|
||||||
@@ -49,7 +63,11 @@ public class GHReleaseBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name the name of the release
|
* Name gh release builder.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name of the release
|
||||||
|
* @return the gh release builder
|
||||||
*/
|
*/
|
||||||
public GHReleaseBuilder name(String name) {
|
public GHReleaseBuilder name(String name) {
|
||||||
builder.with("name", name);
|
builder.with("name", name);
|
||||||
@@ -59,14 +77,23 @@ public class GHReleaseBuilder {
|
|||||||
/**
|
/**
|
||||||
* Optional
|
* Optional
|
||||||
*
|
*
|
||||||
* @param prerelease {@code true} to identify the release as a prerelease. {@code false} to identify the release
|
* @param prerelease
|
||||||
* as a full release. Default is {@code false}.
|
* {@code true} to identify the release as a prerelease. {@code false} to identify the release as a full
|
||||||
|
* release. Default is {@code false}.
|
||||||
|
* @return the gh release builder
|
||||||
*/
|
*/
|
||||||
public GHReleaseBuilder prerelease(boolean prerelease) {
|
public GHReleaseBuilder prerelease(boolean prerelease) {
|
||||||
builder.with("prerelease", prerelease);
|
builder.with("prerelease", prerelease);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create gh release.
|
||||||
|
*
|
||||||
|
* @return the gh release
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHRelease create() throws IOException {
|
public GHRelease create() throws IOException {
|
||||||
return builder.to(repo.getApiTailUrl("releases"), GHRelease.class).wrap(repo);
|
return builder.to(repo.getApiTailUrl("releases"), GHRelease.class).wrap(repo);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.io.IOException;
|
|||||||
* Modifies {@link GHRelease}.
|
* Modifies {@link GHRelease}.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHRelease#update()
|
* @see GHRelease#update() GHRelease#update()
|
||||||
*/
|
*/
|
||||||
public class GHReleaseUpdater {
|
public class GHReleaseUpdater {
|
||||||
private final GHRelease base;
|
private final GHRelease base;
|
||||||
@@ -17,13 +17,24 @@ public class GHReleaseUpdater {
|
|||||||
this.builder = new Requester(base.root);
|
this.builder = new Requester(base.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tag gh release updater.
|
||||||
|
*
|
||||||
|
* @param tag
|
||||||
|
* the tag
|
||||||
|
* @return the gh release updater
|
||||||
|
*/
|
||||||
public GHReleaseUpdater tag(String tag) {
|
public GHReleaseUpdater tag(String tag) {
|
||||||
builder.with("tag_name",tag);
|
builder.with("tag_name", tag);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param body The release notes body.
|
* Body gh release updater.
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* The release notes body.
|
||||||
|
* @return the gh release updater
|
||||||
*/
|
*/
|
||||||
public GHReleaseUpdater body(String body) {
|
public GHReleaseUpdater body(String body) {
|
||||||
builder.with("body", body);
|
builder.with("body", body);
|
||||||
@@ -31,11 +42,11 @@ public class GHReleaseUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the commitish value that determines where the Git tag is created from. Can be any branch or
|
* Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA.
|
||||||
* commit SHA.
|
|
||||||
*
|
*
|
||||||
* @param commitish Defaults to the repository’s default branch (usually "master"). Unused if the Git tag
|
* @param commitish
|
||||||
* already exists.
|
* Defaults to the repository’s default branch (usually "master"). Unused if the Git tag already exists.
|
||||||
|
* @return the gh release updater
|
||||||
*/
|
*/
|
||||||
public GHReleaseUpdater commitish(String commitish) {
|
public GHReleaseUpdater commitish(String commitish) {
|
||||||
builder.with("target_commitish", commitish);
|
builder.with("target_commitish", commitish);
|
||||||
@@ -45,8 +56,10 @@ public class GHReleaseUpdater {
|
|||||||
/**
|
/**
|
||||||
* Optional.
|
* Optional.
|
||||||
*
|
*
|
||||||
* @param draft {@code true} to create a draft (unpublished) release, {@code false} to create a published one.
|
* @param draft
|
||||||
* Default is {@code false}.
|
* {@code true} to create a draft (unpublished) release, {@code false} to create a published one. Default
|
||||||
|
* is {@code false}.
|
||||||
|
* @return the gh release updater
|
||||||
*/
|
*/
|
||||||
public GHReleaseUpdater draft(boolean draft) {
|
public GHReleaseUpdater draft(boolean draft) {
|
||||||
builder.with("draft", draft);
|
builder.with("draft", draft);
|
||||||
@@ -54,7 +67,11 @@ public class GHReleaseUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name the name of the release
|
* Name gh release updater.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the name of the release
|
||||||
|
* @return the gh release updater
|
||||||
*/
|
*/
|
||||||
public GHReleaseUpdater name(String name) {
|
public GHReleaseUpdater name(String name) {
|
||||||
builder.with("name", name);
|
builder.with("name", name);
|
||||||
@@ -64,18 +81,27 @@ public class GHReleaseUpdater {
|
|||||||
/**
|
/**
|
||||||
* Optional
|
* Optional
|
||||||
*
|
*
|
||||||
* @param prerelease {@code true} to identify the release as a prerelease. {@code false} to identify the release
|
* @param prerelease
|
||||||
* as a full release. Default is {@code false}.
|
* {@code true} to identify the release as a prerelease. {@code false} to identify the release as a full
|
||||||
|
* release. Default is {@code false}.
|
||||||
|
* @return the gh release updater
|
||||||
*/
|
*/
|
||||||
public GHReleaseUpdater prerelease(boolean prerelease) {
|
public GHReleaseUpdater prerelease(boolean prerelease) {
|
||||||
builder.with("prerelease", prerelease);
|
builder.with("prerelease", prerelease);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update gh release.
|
||||||
|
*
|
||||||
|
* @return the gh release
|
||||||
|
* @throws IOException
|
||||||
|
* the io exception
|
||||||
|
*/
|
||||||
public GHRelease update() throws IOException {
|
public GHRelease update() throws IOException {
|
||||||
return builder
|
return builder.method("PATCH")
|
||||||
.method("PATCH")
|
.to(base.owner.getApiTailUrl("releases/" + base.id), GHRelease.class)
|
||||||
.to(base.owner.getApiTailUrl("releases/"+base.id), GHRelease.class).wrap(base.owner);
|
.wrap(base.owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ class GHRepoHook extends GHHook {
|
|||||||
/**
|
/**
|
||||||
* Repository that the hook belongs to.
|
* Repository that the hook belongs to.
|
||||||
*/
|
*/
|
||||||
/*package*/ transient GHRepository repository;
|
transient GHRepository repository;
|
||||||
|
|
||||||
/*package*/ GHRepoHook wrap(GHRepository owner) {
|
GHRepoHook wrap(GHRepository owner) {
|
||||||
this.repository = owner;
|
this.repository = owner;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user