Skip to content

Commit 5e2a27a

Browse files
committed
fall out from issue/pull-request unification
1 parent f8d4ec2 commit 5e2a27a

8 files changed

Lines changed: 48 additions & 19 deletions

File tree

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License
33
*
4-
* Copyright (c) 2011, Eric Maupin
4+
* Copyright (c) 2011, Eric Maupin, Kohsuke Kawaguchi
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -24,6 +24,7 @@
2424

2525
package org.kohsuke.github;
2626

27+
import java.io.IOException;
2728
import java.net.URL;
2829
import java.util.Collection;
2930
import java.util.Collections;
@@ -32,16 +33,27 @@
3233
import java.util.Locale;
3334

3435
/**
36+
* Represents an issue on GitHub.
37+
*
3538
* @author Eric Maupin
39+
* @author Kohsuke Kawaguchi
3640
*/
3741
public class GHIssue {
3842
GitHub root;
43+
GHRepository owner;
3944

4045
private String gravatar_id,body,title,state,created_at,updated_at,html_url;
4146
private List<String> labels;
4247
private int number,votes,comments;
4348
private int position;
4449

50+
/**
51+
* Repository to which the issue belongs.
52+
*/
53+
public GHRepository getRepository() {
54+
return owner;
55+
}
56+
4557
/**
4658
* The description of this pull request.
4759
*/
@@ -83,4 +95,12 @@ public Date getCreatedAt() {
8395
public Date getUpdatedAt() {
8496
return GitHub.parseDate(updated_at);
8597
}
98+
99+
/**
100+
* Updates the issue by adding a comment.
101+
*/
102+
public void comment(String message) throws IOException {
103+
new Poster(root).withCredential().with("comment",message).to("/issues/comment/"+
104+
owner.getOwnerName()+"/"+owner.getName()+"/"+number);
105+
}
86106
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
55
import com.gargoylesoftware.htmlunit.html.HtmlForm;
66
import com.gargoylesoftware.htmlunit.html.HtmlPage;
7-
import org.kohsuke.github.GHPullRequest.State;
87

98
import java.io.IOException;
109
import java.util.ArrayList;
@@ -88,7 +87,7 @@ public List<GHRepository> getRepositoriesWithOpenPullRequests() throws IOExcepti
8887
public List<GHPullRequest> getPullRequests() throws IOException {
8988
List<GHPullRequest> all = new ArrayList<GHPullRequest>();
9089
for (GHRepository r : getRepositoriesWithOpenPullRequests()) {
91-
all.addAll(r.getPullRequests(State.OPEN));
90+
all.addAll(r.getPullRequests(GHIssueState.OPEN));
9291
}
9392
return all;
9493
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ public GHUser getUser() {
5555
return user;
5656
}
5757

58-
/**
59-
* Repository to which the pull request was sent.
60-
*/
61-
public GHRepository getRepository() {
62-
return getBase().getRepository();
63-
}
64-
6558
/**
6659
* This points to where the change should be pulled into,
6760
* but I'm not really sure what exactly it means.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public GHUser getOwner() throws IOException {
8686
}
8787

8888
public List<GHIssue> getIssues(GHIssueState state) throws IOException {
89-
return root.retrieve("/issues/list/" + owner + "/" + name + "/" + state.toString().toLowerCase(), JsonIssues.class).issues;
89+
return root.retrieve("/issues/list/" + owner + "/" + name + "/" + state.toString().toLowerCase(), JsonIssues.class).wrap(this);
9090
}
9191

9292
protected String getOwnerName() {
@@ -259,14 +259,14 @@ public void renameTo(String newName) throws IOException {
259259
* Retrieves a specified pull request.
260260
*/
261261
public GHPullRequest getPullRequest(int i) throws IOException {
262-
return root.retrieveWithAuth("/pulls/" + owner + '/' + name + "/" + i, JsonPullRequest.class).wrap(root);
262+
return root.retrieveWithAuth("/pulls/" + owner + '/' + name + "/" + i, JsonPullRequest.class).wrap(this);
263263
}
264264

265265
/**
266266
* Retrieves all the pull requests of a particular state.
267267
*/
268268
public List<GHPullRequest> getPullRequests(GHIssueState state) throws IOException {
269-
return root.retrieveWithAuth("/pulls/"+owner+'/'+name+"/"+state.name().toLowerCase(Locale.ENGLISH),JsonPullRequests.class).wrap(root);
269+
return root.retrieveWithAuth("/pulls/"+owner+'/'+name+"/"+state.name().toLowerCase(Locale.ENGLISH),JsonPullRequests.class).wrap(this);
270270
}
271271

272272
// this is no different from getPullRequests(OPEN)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,11 @@
2828
* @author Eric Maupin
2929
*/
3030
class JsonIssue {
31-
public GHIssue issue;
31+
GHIssue issue;
32+
33+
GHIssue wrap(GHRepository r) {
34+
issue.owner = r;
35+
issue.root = r.root;
36+
return issue;
37+
}
3238
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,12 @@
2727

2828
class JsonIssues {
2929
List<GHIssue> issues;
30+
31+
public List<GHIssue> wrap(GHRepository owner) {
32+
for (GHIssue issue : issues) {
33+
issue.owner = owner;
34+
issue.root = owner.root;
35+
}
36+
return issues;
37+
}
3038
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
class JsonPullRequest {
3030
public GHPullRequest pull;
3131

32-
public GHPullRequest wrap(GitHub root) {
33-
pull.root = root;
32+
public GHPullRequest wrap(GHRepository owner) {
33+
pull.owner = owner;
34+
pull.root = owner.root;
3435
return pull;
3536
}
3637
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
class JsonPullRequests {
3232
public List<GHPullRequest> pulls;
3333

34-
public List<GHPullRequest> wrap(GitHub root) {
35-
for (GHPullRequest pull : pulls)
36-
pull.root = root;
34+
public List<GHPullRequest> wrap(GHRepository owner) {
35+
for (GHPullRequest pull : pulls) {
36+
pull.owner = owner;
37+
pull.root = owner.root;
38+
}
3739
return pulls;
3840
}
3941
}

0 commit comments

Comments
 (0)