Skip to content

Commit 2f86a9e

Browse files
author
Alex Taylor
committed
Merge remote-tracking branch 'upstream/master' into assertThatIssues
2 parents 12c3a0b + 14f3660 commit 2f86a9e

259 files changed

Lines changed: 13677 additions & 310 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ We love getting PRs, but we hate asking people for the same basic changes every
77
- [ ] Push your changes to a branch other than `master`. Create your PR from that branch.
88
- [ ] Add JavaDocs and other comments
99
- [ ] Write tests that run and pass in CI. See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to capture snapshot data.
10-
- [ ] Run `mvn -P ci install site ` locally. This may reformat your code, commit those changes. If this command doesn't succeed, your change will not pass CI.
10+
- [ ] Run `mvn -P ci install site` locally. This may reformat your code, commit those changes. If this command doesn't succeed, your change will not pass CI.

.github/workflows/maven-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ jobs:
1717
with:
1818
java-version: ${{ matrix.java }}
1919
- name: Maven Download all dependencies
20-
run: mvn -B org.apache.maven.plugins:maven-dependency-plugin:3.1.1:go-offline
20+
run: mvn -B org.apache.maven.plugins:maven-dependency-plugin:3.1.1:go-offline -P ci
2121
- name: Maven Build
2222
run: mvn -B install site -P ci --file pom.xml

pom.xml

Lines changed: 180 additions & 176 deletions
Large diffs are not rendered by default.

src/main/java/org/kohsuke/github/GHOrganization.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public GHRepository createRepository(String name,
8888
*
8989
* <p>
9090
* You use the returned builder to set various properties, then call {@link GHCreateRepositoryBuilder#create()} to
91-
* finally createa repository.
91+
* finally create a repository.
9292
*
9393
* @param name
9494
* the name
@@ -386,7 +386,7 @@ public enum Permission {
386386
* @throws IOException
387387
* the io exception
388388
* @deprecated https://developer.github.com/v3/teams/#create-team deprecates permission field use
389-
* {@link #createTeam(String, Collection)}
389+
* {@link #createTeam(String)}
390390
*/
391391
@Deprecated
392392
public GHTeam createTeam(String name, Permission p, Collection<GHRepository> repositories) throws IOException {
@@ -412,7 +412,7 @@ public GHTeam createTeam(String name, Permission p, Collection<GHRepository> rep
412412
* @throws IOException
413413
* the io exception
414414
* @deprecated https://developer.github.com/v3/teams/#create-team deprecates permission field use
415-
* {@link #createTeam(String, GHRepository...)}
415+
* {@link #createTeam(String)}
416416
*/
417417
@Deprecated
418418
public GHTeam createTeam(String name, Permission p, GHRepository... repositories) throws IOException {
@@ -429,7 +429,9 @@ public GHTeam createTeam(String name, Permission p, GHRepository... repositories
429429
* @return the gh team
430430
* @throws IOException
431431
* the io exception
432+
* @deprecated Use {@link #createTeam(String)} that uses a builder pattern to let you control every aspect.
432433
*/
434+
@Deprecated
433435
public GHTeam createTeam(String name, Collection<GHRepository> repositories) throws IOException {
434436
Requester post = root.createRequest().method("POST").with("name", name);
435437
List<String> repo_names = new ArrayList<String>();
@@ -450,11 +452,28 @@ public GHTeam createTeam(String name, Collection<GHRepository> repositories) thr
450452
* @return the gh team
451453
* @throws IOException
452454
* the io exception
455+
* @deprecated Use {@link #createTeam(String)} that uses a builder pattern to let you control every aspect.
453456
*/
457+
@Deprecated
454458
public GHTeam createTeam(String name, GHRepository... repositories) throws IOException {
455459
return createTeam(name, Arrays.asList(repositories));
456460
}
457461

462+
/**
463+
* Starts a builder that creates a new team.
464+
*
465+
* <p>
466+
* You use the returned builder to set various properties, then call {@link GHTeamBuilder#create()} to finally
467+
* create a team.
468+
*
469+
* @param name
470+
* the name
471+
* @return the gh create repository builder
472+
*/
473+
public GHTeamBuilder createTeam(String name) {
474+
return new GHTeamBuilder(root, login, name);
475+
}
476+
458477
/**
459478
* List up repositories that has some open pull requests.
460479
* <p>

src/main/java/org/kohsuke/github/GHRateLimit.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Objects;
1313
import java.util.logging.Logger;
1414

15+
import javax.annotation.CheckForNull;
1516
import javax.annotation.Nonnull;
1617

1718
import static java.util.logging.Level.FINEST;
@@ -41,7 +42,10 @@ public class GHRateLimit {
4142
public int limit;
4243

4344
/**
44-
* The time at which the current rate limit window resets in UTC epoch seconds. NOTE: that means to
45+
* The time at which the current rate limit window resets in UTC epoch seconds. WARNING: this field was implemented
46+
* using {@link Date#Date(long)} which expects UTC epoch milliseconds, so this Date instance is meaningless as a
47+
* date. To use this field in any meaningful way, it must be converted to a long using {@link Date#getTime()}
48+
* multiplied by 1000.
4549
*
4650
* @deprecated This value should never have been made public. Use {@link #getResetDate()}
4751
*/
@@ -60,13 +64,15 @@ public class GHRateLimit {
6064
@Nonnull
6165
private final Record integrationManifest;
6266

67+
@Nonnull
6368
static GHRateLimit Unknown() {
6469
return new GHRateLimit(new UnknownLimitRecord(),
6570
new UnknownLimitRecord(),
6671
new UnknownLimitRecord(),
6772
new UnknownLimitRecord());
6873
}
6974

75+
@Nonnull
7076
static GHRateLimit fromHeaderRecord(Record header) {
7177
return new GHRateLimit(header, new UnknownLimitRecord(), new UnknownLimitRecord(), new UnknownLimitRecord());
7278
}
@@ -76,6 +82,12 @@ static GHRateLimit fromHeaderRecord(Record header) {
7682
@Nonnull @JsonProperty("search") Record search,
7783
@Nonnull @JsonProperty("graphql") Record graphql,
7884
@Nonnull @JsonProperty("integration_manifest") Record integrationManifest) {
85+
// The Nonnull annotation is ignored by Jackson, we have to check manually
86+
Objects.requireNonNull(core);
87+
Objects.requireNonNull(search);
88+
Objects.requireNonNull(graphql);
89+
Objects.requireNonNull(integrationManifest);
90+
7991
this.core = core;
8092
this.search = search;
8193
this.graphql = graphql;
@@ -84,6 +96,7 @@ static GHRateLimit fromHeaderRecord(Record header) {
8496
// Deprecated fields
8597
this.remaining = core.getRemaining();
8698
this.limit = core.getLimit();
99+
// This is wrong but is how this was implemented. Kept for backward compat.
87100
this.reset = new Date(core.getResetEpochSeconds());
88101
}
89102

@@ -270,9 +283,9 @@ public static class Record {
270283
* the reset epoch seconds
271284
*/
272285
@JsonCreator
273-
public Record(@JsonProperty("limit") int limit,
274-
@JsonProperty("remaining") int remaining,
275-
@JsonProperty("reset") long resetEpochSeconds) {
286+
public Record(@JsonProperty(value = "limit", required = true) int limit,
287+
@JsonProperty(value = "remaining", required = true) int remaining,
288+
@JsonProperty(value = "reset", required = true) long resetEpochSeconds) {
276289
this(limit, remaining, resetEpochSeconds, null);
277290
}
278291

@@ -289,7 +302,7 @@ public Record(@JsonProperty("limit") int limit,
289302
* the updated at
290303
*/
291304
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", justification = "Deprecated")
292-
public Record(int limit, int remaining, long resetEpochSeconds, String updatedAt) {
305+
public Record(int limit, int remaining, long resetEpochSeconds, @CheckForNull String updatedAt) {
293306
this.limit = limit;
294307
this.remaining = remaining;
295308
this.resetEpochSeconds = resetEpochSeconds;
@@ -304,7 +317,7 @@ public Record(int limit, int remaining, long resetEpochSeconds, String updatedAt
304317
* a string date in RFC 1123
305318
* @return reset date based on the passed date
306319
*/
307-
Date recalculateResetDate(String updatedAt) {
320+
Date recalculateResetDate(@CheckForNull String updatedAt) {
308321
long updatedAtEpochSeconds = createdAtEpochSeconds;
309322
if (!StringUtils.isBlank(updatedAt)) {
310323
try {
@@ -319,7 +332,7 @@ Date recalculateResetDate(String updatedAt) {
319332
}
320333

321334
// This may seem odd but it results in an accurate or slightly pessimistic reset date
322-
// based on system time rather than on the system being in sync with the server
335+
// based on system time rather than assuming the system time synchronized with the server
323336
long calculatedSecondsUntilReset = resetEpochSeconds - updatedAtEpochSeconds;
324337
return resetDate = new Date((createdAtEpochSeconds + calculatedSecondsUntilReset) * 1000);
325338
}
@@ -352,7 +365,7 @@ public long getResetEpochSeconds() {
352365
}
353366

354367
/**
355-
* Whether the rate limit reset date indicated by this instance is in the
368+
* Whether the rate limit reset date indicated by this instance is expired
356369
*
357370
* @return true if the rate limit reset date has passed. Otherwise false.
358371
*/

src/main/java/org/kohsuke/github/GHRepositoryStatistics.java

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package org.kohsuke.github;
22

3-
import com.fasterxml.jackson.core.type.TypeReference;
4-
import com.fasterxml.jackson.databind.ObjectMapper;
53
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
64
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
75

86
import java.io.IOException;
9-
import java.io.InputStream;
107
import java.net.URL;
118
import java.util.ArrayList;
9+
import java.util.Arrays;
1210
import java.util.List;
1311
import java.util.NoSuchElementException;
1412

@@ -317,20 +315,17 @@ public URL getHtmlUrl() throws IOException {
317315
* the io exception
318316
*/
319317
public List<CodeFrequency> getCodeFrequency() throws IOException {
320-
// Map to ArrayLists first, since there are no field names in the
318+
// Map to arrays first, since there are no field names in the
321319
// returned JSON.
322320
try {
323-
InputStream stream = root.createRequest().withUrlPath(getApiTailUrl("code_frequency")).fetchStream();
324-
325-
ObjectMapper mapper = new ObjectMapper();
326-
TypeReference<ArrayList<ArrayList<Integer>>> typeRef = new TypeReference<ArrayList<ArrayList<Integer>>>() {
327-
};
328-
ArrayList<ArrayList<Integer>> list = mapper.readValue(stream, typeRef);
321+
Integer[][] list = root.createRequest()
322+
.withUrlPath(getApiTailUrl("code_frequency"))
323+
.fetch(Integer[][].class);
329324

330325
// Convert to proper objects.
331-
ArrayList<CodeFrequency> returnList = new ArrayList<CodeFrequency>();
332-
for (ArrayList<Integer> item : list) {
333-
CodeFrequency cf = new CodeFrequency(item);
326+
List<CodeFrequency> returnList = new ArrayList<>();
327+
for (Integer[] item : list) {
328+
CodeFrequency cf = new CodeFrequency(Arrays.asList(item));
334329
returnList.add(cf);
335330
}
336331

@@ -351,7 +346,7 @@ public static class CodeFrequency {
351346
private int additions;
352347
private int deletions;
353348

354-
private CodeFrequency(ArrayList<Integer> item) {
349+
private CodeFrequency(List<Integer> item) {
355350
week = item.get(0);
356351
additions = item.get(1);
357352
deletions = item.get(2);
@@ -462,17 +457,12 @@ Participation wrapUp(GitHub root) {
462457
public List<PunchCardItem> getPunchCard() throws IOException {
463458
// Map to ArrayLists first, since there are no field names in the
464459
// returned JSON.
465-
InputStream stream = root.createRequest().withUrlPath(getApiTailUrl("punch_card")).fetchStream();
466-
467-
ObjectMapper mapper = new ObjectMapper();
468-
TypeReference<ArrayList<ArrayList<Integer>>> typeRef = new TypeReference<ArrayList<ArrayList<Integer>>>() {
469-
};
470-
ArrayList<ArrayList<Integer>> list = mapper.readValue(stream, typeRef);
460+
Integer[][] list = root.createRequest().withUrlPath(getApiTailUrl("punch_card")).fetch(Integer[][].class);
471461

472462
// Convert to proper objects.
473-
ArrayList<PunchCardItem> returnList = new ArrayList<PunchCardItem>();
474-
for (ArrayList<Integer> item : list) {
475-
PunchCardItem pci = new PunchCardItem(item);
463+
ArrayList<PunchCardItem> returnList = new ArrayList<>();
464+
for (Integer[] item : list) {
465+
PunchCardItem pci = new PunchCardItem(Arrays.asList(item));
476466
returnList.add(pci);
477467
}
478468

@@ -487,7 +477,7 @@ public static class PunchCardItem {
487477
private int hourOfDay;
488478
private int numberOfCommits;
489479

490-
private PunchCardItem(ArrayList<Integer> item) {
480+
private PunchCardItem(List<Integer> item) {
491481
dayOfWeek = item.get(0);
492482
hourOfDay = item.get(1);
493483
numberOfCommits = item.get(2);

src/main/java/org/kohsuke/github/GHTeam.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@
1212
* @author Kohsuke Kawaguchi
1313
*/
1414
public class GHTeam implements Refreshable {
15-
private String name, permission, slug, description;
15+
private String name;
16+
private String permission;
17+
private String slug;
18+
private String description;
19+
private Privacy privacy;
20+
1621
private int id;
1722
private GHOrganization organization; // populated by GET /user/teams where Teams+Orgs are returned together
1823

1924
protected /* final */ GitHub root;
2025

26+
public enum Privacy {
27+
SECRET, // only visible to organization owners and members of this team.
28+
CLOSED // visible to all members of this organization.
29+
}
30+
2131
/**
2232
* Member's role in a team
2333
*/
@@ -94,6 +104,15 @@ public String getDescription() {
94104
return description;
95105
}
96106

107+
/**
108+
* Gets the privacy state.
109+
*
110+
* @return the privacy state.
111+
*/
112+
public Privacy getPrivacy() {
113+
return privacy;
114+
}
115+
97116
/**
98117
* Sets description.
99118
*
@@ -106,6 +125,18 @@ public void setDescription(String description) throws IOException {
106125
root.createRequest().method("PATCH").with("description", description).withUrlPath(api("")).send();
107126
}
108127

128+
/**
129+
* Updates the team's privacy setting.
130+
*
131+
* @param privacy
132+
* the privacy
133+
* @throws IOException
134+
* the io exception
135+
*/
136+
public void setPrivacy(Privacy privacy) throws IOException {
137+
root.createRequest().method("PATCH").with("privacy", privacy).withUrlPath(api("")).send();
138+
}
139+
109140
/**
110141
* Gets id.
111142
*

0 commit comments

Comments
 (0)