Skip to content

Commit dab0f0e

Browse files
authored
Source repo owner (#300)
* Source repo owner * Update tests * Update tests
1 parent 92d088a commit dab0f0e

File tree

11 files changed

+59
-7
lines changed

11 files changed

+59
-7
lines changed

.idea/encodings.xml

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/GitHubPRPullRequest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.apache.commons.lang3.builder.EqualsBuilder;
55
import org.apache.commons.lang3.builder.HashCodeBuilder;
66
import org.apache.commons.lang3.builder.ToStringBuilder;
7+
import org.kohsuke.github.GHCommitPointer;
78
import org.kohsuke.github.GHIssueComment;
89
import org.kohsuke.github.GHLabel;
910
import org.kohsuke.github.GHPullRequest;
@@ -68,8 +69,12 @@ public GitHubPRPullRequest(GHPullRequest pr) {
6869
// those methods never actually throw IOExceptions
6970
throw new IllegalStateException(e);
7071
}
71-
headSha = pr.getHead().getSha();
72-
headRef = pr.getHead().getRef();
72+
73+
GHCommitPointer prHead = pr.getHead();
74+
headSha = prHead.getSha();
75+
headRef = prHead.getRef();
76+
sourceRepoOwner = prHead.getRepository().getOwnerName();
77+
7378
title = pr.getTitle();
7479
baseRef = pr.getBase().getRef();
7580
htmlUrl = pr.getHtmlUrl();
@@ -112,7 +117,6 @@ public GitHubPRPullRequest(GHPullRequest pr) {
112117
mergeable = false;
113118
}
114119

115-
sourceRepoOwner = remoteRepo.getOwnerName();
116120
state = pr.getState().toString();
117121
body = pr.getBody();
118122
}

github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github/pullrequest/events/impl/GitHubPRCommentEventTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,10 @@ private void commonExpectations(Set<String> localLabels) throws IOException {
214214
private void causeCreationExpectations() throws IOException {
215215
GHUser mockUser = mock(GHUser.class);
216216
GHCommitPointer mockPointer = mock(GHCommitPointer.class);
217+
GHRepository headRepo = mock(GHRepository.class);
218+
when(headRepo.getOwnerName()).thenReturn("owner");
217219

220+
when(mockPointer.getRepository()).thenReturn(headRepo);
218221
when(remotePr.getUser()).thenReturn(mockUser);
219222
when(remotePr.getHead()).thenReturn(mockPointer);
220223
when(remotePr.getBase()).thenReturn(mockPointer);

github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github/pullrequest/events/impl/GitHubPRDescriptionEventTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ private void causeCreationExpectations() throws IOException {
116116
GHUser mockUser = mock(GHUser.class);
117117
GHCommitPointer mockPointer = mock(GHCommitPointer.class);
118118

119+
GHRepository headRepo = mock(GHRepository.class);
120+
when(headRepo.getOwnerName()).thenReturn("owner");
121+
122+
when(mockPointer.getRepository()).thenReturn(headRepo);
123+
119124
when(remotePr.getUser()).thenReturn(mockUser);
120125
when(remotePr.getHead()).thenReturn(mockPointer);
121126
when(remotePr.getBase()).thenReturn(mockPointer);

github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github/pullrequest/events/impl/GitHubPRLabelExistsEventTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ private void causeCreationExpectations() throws IOException {
273273
GHUser mockUser = mock(GHUser.class);
274274
GHCommitPointer mockPointer = mock(GHCommitPointer.class);
275275

276+
GHRepository headRepo = mock(GHRepository.class);
277+
when(headRepo.getOwnerName()).thenReturn("owner");
278+
279+
when(mockPointer.getRepository()).thenReturn(headRepo);
280+
276281
when(remotePr.getUser()).thenReturn(mockUser);
277282
when(remotePr.getHead()).thenReturn(mockPointer);
278283
when(remotePr.getBase()).thenReturn(mockPointer);

github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github/pullrequest/events/impl/GitHubPRLabelNotExistsEventTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@ private void causeCreationExpectations() throws IOException {
272272
GHUser mockUser = mock(GHUser.class);
273273
GHCommitPointer mockPointer = mock(GHCommitPointer.class);
274274

275+
GHRepository headRepo = mock(GHRepository.class);
276+
when(headRepo.getOwnerName()).thenReturn("owner");
277+
278+
when(mockPointer.getRepository()).thenReturn(headRepo);
279+
275280
when(remotePr.getUser()).thenReturn(mockUser);
276281
when(remotePr.getHead()).thenReturn(mockPointer);
277282
when(remotePr.getBase()).thenReturn(mockPointer);

github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github/pullrequest/events/impl/GitHubPRLabelRemovedEventTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class GitHubPRLabelRemovedEventTest {
5050
@Mock
5151
private GHRepository repository;
5252
@Mock
53+
private GHRepository headRepository;
54+
@Mock
5355
private GHIssue issue;
5456
@Mock
5557
private GHLabel label;
@@ -162,7 +164,8 @@ private void commonExpectations(Set<String> localLabels) throws IOException {
162164
private void causeCreationExpectations() throws IOException {
163165
GHUser mockUser = mock(GHUser.class);
164166
GHCommitPointer mockPointer = mock(GHCommitPointer.class);
165-
167+
when(mockPointer.getRepository()).thenReturn(headRepository);
168+
when(headRepository.getOwnerName()).thenReturn("owner");
166169
when(remotePr.getUser()).thenReturn(mockUser);
167170
when(remotePr.getHead()).thenReturn(mockPointer);
168171
when(remotePr.getBase()).thenReturn(mockPointer);

github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github/pullrequest/events/impl/GitHubPRNonMergeableEventTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.junit.Assert.assertNotNull;
2525
import static org.junit.Assert.assertNull;
2626
import static org.junit.Assert.assertTrue;
27+
import static org.mockito.Mockito.mock;
2728
import static org.mockito.Mockito.when;
2829

2930
/**
@@ -54,10 +55,17 @@ public class GitHubPRNonMergeableEventTest {
5455
@Before
5556
public void before() throws IOException {
5657
when(remotePr.getUser()).thenReturn(ghUser);
58+
59+
GHRepository headRepo = mock(GHRepository.class);
60+
when(headRepo.getOwnerName()).thenReturn("owner");
61+
5762
when(remotePr.getHead()).thenReturn(ghCommitPointer);
5863
when(remotePr.getBase()).thenReturn(ghCommitPointer);
64+
5965
when(ghCommitPointer.getSha()).thenReturn("1r134rsha324");
6066
when(ghCommitPointer.getRef()).thenReturn("some/branch");
67+
when(ghCommitPointer.getRepository()).thenReturn(headRepo);
68+
6169
when(remotePr.getRepository()).thenReturn(ghRepository);
6270
when(ghRepository.getIssue(0)).thenReturn(ghIssue);
6371
when(ghIssue.getLabels()).thenReturn(Collections.<GHLabel>emptySet());

github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github/pullrequest/events/impl/GitHubPRNumberTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ private void commonExpectations() throws IOException {
167167
}
168168

169169
private void causeCreationExpectations() throws IOException {
170+
GHRepository headRepo = mock(GHRepository.class);
171+
when(headRepo.getOwnerName()).thenReturn("owner");
172+
173+
when(mockPointer.getRepository()).thenReturn(headRepo);
174+
170175
when(remotePr.getUser()).thenReturn(mockUser);
171176
when(remotePr.getHead()).thenReturn(mockPointer);
172177
when(remotePr.getBase()).thenReturn(mockPointer);

github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github/pullrequest/trigger/check/LocalRepoUpdaterTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.hamcrest.Matchers.hasKey;
2222
import static org.hamcrest.Matchers.is;
2323
import static org.hamcrest.Matchers.not;
24+
import static org.mockito.Mockito.mock;
2425
import static org.mockito.Mockito.when;
2526

2627
/**
@@ -49,6 +50,12 @@ public class LocalRepoUpdaterTest {
4950
public void setUp() throws Exception {
5051
localRepo = new GitHubPRRepository(remoteRepo);
5152

53+
GHRepository headRepo = mock(GHRepository.class);
54+
when(headRepo.getOwnerName()).thenReturn("owner");
55+
56+
when(commit.getRepository()).thenReturn(headRepo);
57+
58+
5259
when(remotePR.getUser()).thenReturn(new GHUser());
5360
when(remotePR.getHead()).thenReturn(commit);
5461
when(remotePR.getBase()).thenReturn(commit);

0 commit comments

Comments
 (0)