-
Notifications
You must be signed in to change notification settings - Fork 374
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
Draft
janfaracik
wants to merge
23
commits into
jenkinsci:master
Choose a base branch
from
janfaracik:detail-widget
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
23 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 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
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
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.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; | ||
|
||
public class GitHubCommitDetail extends Detail { | ||
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) { | ||
return abstractRevision.getHash().substring(0, 7); | ||
} else if (revision instanceof PullRequestSCMRevision pullRequestSCMRevision) { | ||
return pullRequestSCMRevision.getPullHash().substring(0, 7); | ||
} | ||
|
||
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; | ||
} | ||
|
||
// TODO - ends with .git | ||
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; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
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,40 @@ | ||
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.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; | ||
|
||
public class GitHubRepositoryDetail extends Detail { | ||
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; | ||
} | ||
|
||
@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; | ||
} | ||
|
||
// TODO - Has .git on the end | ||
return source.getRepositoryUrl(); | ||
} | ||
|
||
@Override | ||
public DetailGroup getGroup() { | ||
return ScmDetailGroup.get(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/jenkinsci/plugins/github_branch_source/ScmDetailGroup.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,14 @@ | ||
package org.jenkinsci.plugins.github_branch_source; | ||
|
||
import hudson.Extension; | ||
import hudson.ExtensionList; | ||
import jenkins.model.details.DetailGroup; | ||
|
||
// TODO - Should be moved to parent plugin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be moved to scm-api I think? |
||
@Extension(ordinal = -1) | ||
public class ScmDetailGroup extends DetailGroup { | ||
|
||
public static ScmDetailGroup get() { | ||
return ExtensionList.lookupSingleton(ScmDetailGroup.class); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potentially belongs in the Git plugin? and then this plugin only handles the pull request one?
Although not sure if you could figure out the link from there, maybe you can though?