Skip to content

Commit bcd1374

Browse files
authored
Get branch directly, exclude load of everythign (#250)
* Get branch directly, exclude load of everythign * Fix test
1 parent 90375a2 commit bcd1374

4 files changed

Lines changed: 41 additions & 3 deletions

File tree

github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/branch/GitHubBranchTrigger.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import javax.annotation.CheckForNull;
2929
import javax.annotation.Nonnull;
3030
import javax.annotation.Nullable;
31+
import java.io.FileNotFoundException;
3132
import java.io.IOException;
3233
import java.util.ArrayList;
3334
import java.util.Date;
@@ -257,10 +258,14 @@ private Set<GHBranch> branchesToCheck(@CheckForNull String branch, @Nonnull GHRe
257258
final LinkedHashSet<GHBranch> ghBranches = new LinkedHashSet<>();
258259

259260
if (branch != null) {
260-
final GHBranch ghBranch = remoteRepo.getBranches().get(branch);
261-
if (ghBranch != null) {
262-
ghBranches.add(ghBranch);
261+
try {
262+
GHBranch ghBranch = remoteRepo.getBranch(branch);
263+
if (ghBranch != null) {
264+
ghBranches.add(ghBranch);
265+
}
266+
} catch (FileNotFoundException ignore) {
263267
}
268+
264269
} else {
265270
ghBranches.addAll(remoteRepo.getBranches().values());
266271
}

github-pullrequest-plugin/src/test/java/com/github/kostyasha/github/integration/branch/GitHubBranchTriggerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class GitHubBranchTriggerTest {
5151
))
5252
.stubRateLimit()
5353
.stubUser()
54+
.stubRepoBranchShouldChange()
5455
.stubRepoBranches()
5556
.stubRepo()
5657
.stubStatuses();

github-pullrequest-plugin/src/test/java/com/github/kostyasha/github/integration/branch/test/GHMockRule.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ public GHMockRule stubRepoBranches() {
114114
});
115115
}
116116

117+
public GHMockRule stubRepoBranchShouldChange() {
118+
return addSetup(() -> {
119+
String repo = format("/repos/%s/%s/branches/should-change", REPO.getUserName(), REPO.getRepositoryName());
120+
service().stubFor(
121+
get(urlEqualTo(repo))
122+
.willReturn(aResponse()
123+
.withStatus(200)
124+
.withHeader("Content-Type", "application/json; charset=utf-8")
125+
.withBody(classpath(GHMockRule.class, "branch-should-change.json"))));
126+
});
127+
}
128+
117129
/**
118130
* Stubs /repos/org/repo response with predefined content
119131
* <p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "should-change",
3+
"commit": {
4+
"sha": "6dcb09b5b57875f334f61aebed695e2e4193ffgg",
5+
"commit": {
6+
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193ffgg",
7+
"message": "Merge pull request #6 from Spaceghost/patch-1\n\nNew line at end of file."
8+
},
9+
"url": "https://api.github.com/repos/octocat/Hello-World/commits/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
10+
"committer": {
11+
"gravatar_id": "",
12+
"avatar_url": "https://secure.gravatar.com/avatar/7ad39074b0584bc555d0417ae3e7d974?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
13+
"url": "https://api.github.com/users/octocat",
14+
"id": 583231,
15+
"login": "octocat"
16+
}
17+
},
18+
"protected": true,
19+
"protection_url": "https://api.github.com/repos/octocat/Hello-World/branches/should-change/protection"
20+
}

0 commit comments

Comments
 (0)