Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for merge_commit_sha #231

Merged
merged 5 commits into from
Nov 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/main/java/org/kohsuke/github/GHPullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class GHPullRequest extends GHIssue {
private int deletions;
private String mergeable_state;
private int changed_files;
private String merge_commit_sha;

/**
* GitHub doesn't return some properties of {@link GHIssue} when requesting the GET on the 'pulls' API
Expand Down Expand Up @@ -142,9 +143,9 @@ public PullRequest getPullRequest() {
}

//
// details that are only available via get with ID
//
//
// details that are only available via get with ID
//
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated changes but...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to convert the comment to Javadoc then :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really, it is not a method comment, only a note in the middle of the file.


public GHUser getMergedBy() throws IOException {
populate();
return merged_by;
Expand Down Expand Up @@ -185,6 +186,14 @@ public int getChangedFiles() throws IOException {
return changed_files;
}

/**
* See <a href="https://developer.github.com/changes/2013-04-25-deprecating-merge-commit-sha">GitHub blog post</a>
*/
public String getMergeCommitSha() throws IOException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the field disappears? Does the method return null in such case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this happens, GitHub API v4 will be released and we should review the current status (compatibility).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oleg-nenashev Any recommendation here to improve it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oleg-nenashev I've checked that if your model has an attribute and is not mapped in the JSON, its get() method returns null. I think that is ok.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. This line is preventing to fail on missing properties.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oleg-nenashev @CheckForNull?

populate();
return merge_commit_sha;
}

/**
* Fully populate the data by retrieving missing data.
*
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/kohsuke/github/PullRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public void testPullRequestReviewComments() throws Exception {
assertTrue(comments.isEmpty());
}

@Test
public void testMergeCommitSHA() throws Exception {
String name = rnd.next();
GHPullRequest p = getRepository().createPullRequest(name, "stable", "master", "## test");
GHPullRequest updated = getRepository().getPullRequest(p.getNumber());
GHCommit commit = getRepository().getCommit(updated.getMergeCommitSha());
assertNotNull(commit);
}

@Test
// Requires push access to the test repo to pass
public void setLabels() throws Exception {
Expand Down