-
Notifications
You must be signed in to change notification settings - Fork 384
Add GitHub branch and pull request info to the 'Details' widget #826
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
Merged
Merged
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
22269dd
Init
janfaracik 2972f60
Update pom.xml
janfaracik 70a2ec0
Push
janfaracik 6aab691
Update GitHubDetailFactory.java
janfaracik 1a83038
Simplify
janfaracik e00614a
Update GitHubBranchDetail.java
janfaracik d9e54f5
Update GitHubBranchDetail.java
janfaracik 84f30a8
Semi working
janfaracik c5ea7ac
Update GitHubRepositoryDetail.java
janfaracik bdc8c7c
Update GitHubRepositoryDetail.java
janfaracik 95a0202
Update GitHubPullRequestDetail.java
janfaracik 63816db
Rough null checks...
janfaracik 461177d
Spotless
janfaracik c87badb
Tidy up
janfaracik c755701
Update GitHubBranchDetail.java
janfaracik 8e25978
Fix a few things
janfaracik e66c0e3
Drop isApplicable
janfaracik 2a57ab6
Update GitHubDetailFactory.java
janfaracik dafc5c4
Update GitHubDetailFactory.java
janfaracik d90b1a9
Push
janfaracik 857feaa
Update pom.xml
janfaracik b2212c7
Merge branch 'master' into detail-widget
janfaracik 9f37620
Update GitHubRepositoryDetail.java
janfaracik 7f0e5bf
Merge branch 'master' into detail-widget
janfaracik f3f8e59
Push
janfaracik d01e501
Remove comments
janfaracik 2abc5b2
Update group
janfaracik ab18842
Merge branch 'master' into detail-widget
timja 24e27b7
Update pom.xml
timja 24ab3d1
Refine code, add tests
janfaracik d48c6a0
Spotless
janfaracik 1e546fd
Update GitHubRepositoryDetail.java
janfaracik 43592e6
Merge branch 'master' into detail-widget
janfaracik da8130c
Refine
janfaracik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubBranchDetail.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package org.jenkinsci.plugins.github_branch_source; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.Nullable; | ||
| import hudson.model.Actionable; | ||
| import hudson.model.Run; | ||
| import jenkins.model.details.Detail; | ||
| import jenkins.model.details.DetailGroup; | ||
| import jenkins.scm.api.SCMHead; | ||
| import jenkins.scm.api.SCMRevision; | ||
| import jenkins.scm.api.SCMRevisionAction; | ||
| import jenkins.scm.api.ScmDetailGroup; | ||
| import jenkins.scm.api.metadata.ObjectMetadataAction; | ||
|
|
||
| public class GitHubBranchDetail extends Detail { | ||
| public GitHubBranchDetail(Actionable object) { | ||
| super(object); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public String getIconClassName() { | ||
| return "symbol-git-branch-outline plugin-ionicons-api"; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public String getDisplayName() { | ||
| SCMRevisionAction scmRevisionAction = getObject().getAction(SCMRevisionAction.class); | ||
| SCMRevision revision = scmRevisionAction.getRevision(); | ||
|
|
||
| if (revision instanceof PullRequestSCMRevision pullRequestSCMRevision) { | ||
| PullRequestSCMHead head = (PullRequestSCMHead) pullRequestSCMRevision.getHead(); | ||
| return head.getSourceBranch(); | ||
| } | ||
|
|
||
| SCMHead head = revision.getHead(); | ||
| return head.getName(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getLink() { | ||
| var run = (Run<?, ?>) getObject(); | ||
| ObjectMetadataAction action = run.getParent().getAction(ObjectMetadataAction.class); | ||
| return action.getObjectUrl(); | ||
| } | ||
|
|
||
| @Override | ||
| public DetailGroup getGroup() { | ||
| return ScmDetailGroup.get(); | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubCommitDetail.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package org.jenkinsci.plugins.github_branch_source; | ||
|
|
||
| import hudson.model.Actionable; | ||
| import hudson.model.Run; | ||
| import jenkins.model.details.Detail; | ||
| import jenkins.model.details.DetailGroup; | ||
| import jenkins.plugins.git.AbstractGitSCMSource; | ||
| import jenkins.scm.api.SCMRevision; | ||
| import jenkins.scm.api.SCMRevisionAction; | ||
| import jenkins.scm.api.SCMSource; | ||
| import jenkins.scm.api.ScmDetailGroup; | ||
|
|
||
| public class GitHubCommitDetail extends Detail { | ||
timja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public GitHubCommitDetail(Actionable object) { | ||
| super(object); | ||
| } | ||
|
|
||
| public String getIconClassName() { | ||
| return "symbol-git-commit-outline plugin-ionicons-api"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDisplayName() { | ||
| SCMRevisionAction scmRevisionAction = getObject().getAction(SCMRevisionAction.class); | ||
| SCMRevision revision = scmRevisionAction.getRevision(); | ||
|
|
||
| if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl abstractRevision) { | ||
timja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return abstractRevision.getHash().substring(0, 7); | ||
| } else if (revision instanceof PullRequestSCMRevision pullRequestSCMRevision) { | ||
| return pullRequestSCMRevision.getPullHash().substring(0, 7); | ||
timja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public String getLink() { | ||
| SCMRevisionAction scmRevisionAction = getObject().getAction(SCMRevisionAction.class); | ||
| SCMRevision revision = scmRevisionAction.getRevision(); | ||
|
|
||
| if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl abstractRevision) { | ||
| GitHubSCMSource src = (GitHubSCMSource) SCMSource.SourceByItem.findSource(((Run) getObject()).getParent()); | ||
|
|
||
| if (src == null) { | ||
| return null; | ||
| } | ||
|
|
||
| return src.getRepositoryUrl() + "/commit/" + abstractRevision.getHash(); | ||
| } else if (revision instanceof PullRequestSCMRevision pullRequestSCMRevision) { | ||
| var run = (Run<?, ?>) getObject(); | ||
| GitHubLink repoLink = run.getParent().getAction(GitHubLink.class); | ||
| return repoLink.getUrl() + "/commits/" + pullRequestSCMRevision.getPullHash(); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public DetailGroup getGroup() { | ||
| return ScmDetailGroup.get(); | ||
| } | ||
| } | ||
45 changes: 45 additions & 0 deletions
45
src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubDetailFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package org.jenkinsci.plugins.github_branch_source; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.NonNull; | ||
| import hudson.Extension; | ||
| import hudson.model.Run; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import jenkins.model.details.Detail; | ||
| import jenkins.model.details.DetailFactory; | ||
| import jenkins.scm.api.SCMRevision; | ||
| import jenkins.scm.api.SCMRevisionAction; | ||
|
|
||
| @Extension | ||
| public final class GitHubDetailFactory extends DetailFactory<Run> { | ||
|
|
||
| @Override | ||
| public Class<Run> type() { | ||
| return Run.class; | ||
| } | ||
|
|
||
| @NonNull | ||
| @Override | ||
| public List<? extends Detail> createFor(@NonNull Run target) { | ||
| SCMRevisionAction scmRevisionAction = target.getAction(SCMRevisionAction.class); | ||
| if (scmRevisionAction == null) { | ||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| List<Detail> details = new ArrayList<>(); | ||
|
|
||
| SCMRevision revision = scmRevisionAction.getRevision(); | ||
|
|
||
| if (revision instanceof PullRequestSCMRevision) { | ||
| details.add(new GitHubPullRequestDetail(target)); | ||
| } else { | ||
| details.add(new GitHubBranchDetail(target)); | ||
| } | ||
|
|
||
| details.add(new GitHubCommitDetail(target)); | ||
| details.add(new GitHubRepositoryDetail(target)); | ||
|
|
||
| return details; | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubPullRequestDetail.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package org.jenkinsci.plugins.github_branch_source; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.Nullable; | ||
| import hudson.model.Actionable; | ||
| import hudson.model.Run; | ||
| import jenkins.model.details.Detail; | ||
| import jenkins.model.details.DetailGroup; | ||
| import jenkins.scm.api.ScmDetailGroup; | ||
| import jenkins.scm.api.metadata.ObjectMetadataAction; | ||
|
|
||
| public class GitHubPullRequestDetail extends Detail { | ||
| public GitHubPullRequestDetail(Actionable object) { | ||
| super(object); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public String getIconClassName() { | ||
| return "symbol-git-pull-request-outline plugin-ionicons-api"; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public String getDisplayName() { | ||
| var run = (Run<?, ?>) getObject(); | ||
| ObjectMetadataAction action = run.getParent().getAction(ObjectMetadataAction.class); | ||
| return action.getObjectDisplayName(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getLink() { | ||
| var run = (Run<?, ?>) getObject(); | ||
| GitHubLink repoLink = run.getParent().getAction(GitHubLink.class); | ||
| return repoLink.getUrl(); | ||
| } | ||
|
|
||
| @Override | ||
| public DetailGroup getGroup() { | ||
| return ScmDetailGroup.get(); | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubRepositoryDetail.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package org.jenkinsci.plugins.github_branch_source; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.Nullable; | ||
| import hudson.model.Actionable; | ||
| import hudson.model.Run; | ||
| import jenkins.model.details.Detail; | ||
| import jenkins.model.details.DetailGroup; | ||
| import jenkins.scm.api.SCMSource; | ||
| import jenkins.scm.api.ScmDetailGroup; | ||
|
|
||
| public class GitHubRepositoryDetail extends Detail { | ||
janfaracik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public GitHubRepositoryDetail(Actionable object) { | ||
| super(object); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public String getIconClassName() { | ||
| return "symbol-logo-github plugin-ionicons-api"; | ||
| } | ||
|
|
||
| private GitHubSCMSource getSCMSource() { | ||
| var source = SCMSource.SourceByItem.findSource(((Run) getObject()).getParent()); | ||
|
|
||
| if (!(source instanceof GitHubSCMSource)) { | ||
| return null; | ||
| } | ||
|
|
||
| return (GitHubSCMSource) source; | ||
janfaracik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public String getDisplayName() { | ||
| GitHubSCMSource source = getSCMSource(); | ||
|
|
||
| if (source == null) { | ||
| return null; | ||
| } | ||
|
|
||
| return source.getRepoOwner() + "/" + source.getRepository(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getLink() { | ||
| GitHubSCMSource source = getSCMSource(); | ||
|
|
||
| if (source == null) { | ||
| return null; | ||
| } | ||
|
|
||
| return source.getRepositoryUrl(); | ||
| } | ||
|
|
||
| @Override | ||
| public DetailGroup getGroup() { | ||
| return ScmDetailGroup.get(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.