-
Notifications
You must be signed in to change notification settings - Fork 400
Allow for commit status backref configuration #138
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
25 changes: 25 additions & 0 deletions
25
src/main/java/org/jenkinsci/plugins/github/extension/status/GitHubStatusBackrefSource.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,25 @@ | ||
| package org.jenkinsci.plugins.github.extension.status; | ||
|
|
||
| import hudson.ExtensionPoint; | ||
| import hudson.model.AbstractDescribableImpl; | ||
| import hudson.model.Run; | ||
| import hudson.model.TaskListener; | ||
|
|
||
| /** | ||
| * Extension point to provide backref for the status, i.e. to the build or to the test report. | ||
| * | ||
| * @author pupssman (Kalinin Ivan) | ||
| * @since 1.21.2 | ||
| */ | ||
| public abstract class GitHubStatusBackrefSource extends AbstractDescribableImpl<GitHubStatusBackrefSource> | ||
| implements ExtensionPoint { | ||
|
|
||
| /** | ||
| * @param run actual run | ||
| * @param listener build listener | ||
| * | ||
| * @return URL that points to the status source, i.e. test result page | ||
| */ | ||
| public abstract String get(Run<?, ?> run, TaskListener listener); | ||
|
|
||
| } |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/org/jenkinsci/plugins/github/status/sources/BuildRefBackrefSource.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,35 @@ | ||
| package org.jenkinsci.plugins.github.status.sources; | ||
|
|
||
| import org.jenkinsci.plugins.github.extension.status.GitHubStatusBackrefSource; | ||
|
|
||
| import hudson.Extension; | ||
| import hudson.model.Descriptor; | ||
| import hudson.model.Run; | ||
| import hudson.model.TaskListener; | ||
|
|
||
| /** | ||
| * Gets backref from Run URL. | ||
| * | ||
| * @author pupssman (Kalinin Ivan) | ||
| * @since 1.21.2 | ||
| * | ||
| */ | ||
| public class BuildRefBackrefSource extends GitHubStatusBackrefSource { | ||
|
|
||
| /** | ||
| * Returns absolute URL of the Run | ||
| */ | ||
| @SuppressWarnings("deprecation") | ||
| @Override | ||
| public String get(Run<?, ?> run, TaskListener listener) { | ||
| return run.getAbsoluteUrl(); | ||
| } | ||
|
|
||
| @Extension | ||
| public static class BuildRefBackrefSourceDescriptor extends Descriptor<GitHubStatusBackrefSource> { | ||
| @Override | ||
| public String getDisplayName() { | ||
| return "Backref to the build"; | ||
| } | ||
| } | ||
| } | ||
57 changes: 57 additions & 0 deletions
57
src/main/java/org/jenkinsci/plugins/github/status/sources/ManuallyEnteredBackrefSource.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,57 @@ | ||
| package org.jenkinsci.plugins.github.status.sources; | ||
|
|
||
| import org.jenkinsci.plugins.github.common.ExpandableMessage; | ||
| import org.jenkinsci.plugins.github.extension.status.GitHubStatusBackrefSource; | ||
| import org.kohsuke.stapler.DataBoundConstructor; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import hudson.Extension; | ||
| import hudson.model.Descriptor; | ||
| import hudson.model.Run; | ||
| import hudson.model.TaskListener; | ||
|
|
||
| /** | ||
| * Allows to manually enter backref, with env/token expansion. | ||
| * | ||
| * @author pupssman (Kalinin Ivan) | ||
| * @since 1.21.2 | ||
| * | ||
| */ | ||
| public class ManuallyEnteredBackrefSource extends GitHubStatusBackrefSource { | ||
| private static final Logger LOG = LoggerFactory.getLogger(ManuallyEnteredBackrefSource.class); | ||
|
|
||
| private String backref; | ||
|
|
||
| @DataBoundConstructor | ||
| public ManuallyEnteredBackrefSource(String backref) { | ||
| this.backref = backref; | ||
| } | ||
|
|
||
| public String getBackref() { | ||
| return backref; | ||
| } | ||
|
|
||
| /** | ||
| * Just returns what user entered. Expands env vars and token macro | ||
| */ | ||
| @SuppressWarnings("deprecation") | ||
| @Override | ||
| public String get(Run<?, ?> run, TaskListener listener) { | ||
| try { | ||
| return new ExpandableMessage(backref).expandAll(run, listener); | ||
| } catch (Exception e) { | ||
| LOG.debug("Can't expand backref, returning as is", e); | ||
| return backref; | ||
| } | ||
| } | ||
|
|
||
| @Extension | ||
| public static class ManuallyEnteredBackrefSourceDescriptor extends Descriptor<GitHubStatusBackrefSource> { | ||
| @Override | ||
| public String getDisplayName() { | ||
| return "Manually entered backref"; | ||
| } | ||
| } | ||
|
|
||
| } |
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
7 changes: 7 additions & 0 deletions
7
...resources/org/jenkinsci/plugins/github/status/sources/BuildRefBackrefSource/config.groovy
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,7 @@ | ||
| package org.jenkinsci.plugins.github.status.sources.BuildRefBackrefSource | ||
|
|
||
|
|
||
| def f = namespace(lib.FormTagLib); | ||
|
|
||
| f.helpLink(url: descriptor.getHelpFile()) | ||
| f.helpArea() |
3 changes: 3 additions & 0 deletions
3
...ain/resources/org/jenkinsci/plugins/github/status/sources/BuildRefBackrefSource/help.html
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,3 @@ | ||
| <div> | ||
| Points commit status backref back to the producing build page. | ||
| </div> |
8 changes: 8 additions & 0 deletions
8
...es/org/jenkinsci/plugins/github/status/sources/ManuallyEnteredBackrefSource/config.groovy
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,8 @@ | ||
| package org.jenkinsci.plugins.github.status.sources.ManuallyEnteredBackrefSource | ||
|
|
||
|
|
||
| def f = namespace(lib.FormTagLib); | ||
|
|
||
| f.entry(title: _('Backref URL'), field: 'backref') { | ||
| f.textbox() | ||
| } |
3 changes: 3 additions & 0 deletions
3
...rg/jenkinsci/plugins/github/status/sources/ManuallyEnteredBackrefSource/help-backref.html
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,3 @@ | ||
| <div> | ||
| A backref URL. Allows env vars and token macro. | ||
| </div> |
3 changes: 3 additions & 0 deletions
3
...ources/org/jenkinsci/plugins/github/status/sources/ManuallyEnteredBackrefSource/help.html
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,3 @@ | ||
| <div> | ||
| A manually entered backref URL. | ||
| </div> |
45 changes: 45 additions & 0 deletions
45
src/test/java/org/jenkinsci/plugins/github/status/sources/BuildRefBackrefSourceTest.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.status.sources; | ||
|
|
||
| import hudson.model.FreeStyleProject; | ||
| import hudson.model.Run; | ||
| import hudson.model.TaskListener; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.jvnet.hudson.test.JenkinsRule; | ||
| import org.mockito.Answers; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.MockitoJUnit; | ||
| import org.mockito.junit.MockitoRule; | ||
| import org.mockito.runners.MockitoJUnitRunner; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.is; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| /** | ||
| * @author pupssman (Kalinin Ivan) | ||
| */ | ||
| @RunWith(MockitoJUnitRunner.class) | ||
| public class BuildRefBackrefSourceTest { | ||
|
|
||
| @Rule | ||
| public JenkinsRule jenkinsRule = new JenkinsRule(); | ||
|
|
||
| @Mock(answer = Answers.RETURNS_MOCKS) | ||
| private TaskListener listener; | ||
|
|
||
| @Test | ||
| /** | ||
| * Should've used mocked Run, but getAbsoluteUrl is final. | ||
| * | ||
| * @throws Exception | ||
| */ | ||
| public void shouldReturnRunAbsoluteUrl() throws Exception { | ||
| Run<?, ?> run = jenkinsRule.buildAndAssertSuccess(jenkinsRule.createFreeStyleProject()); | ||
|
|
||
| String result = new BuildRefBackrefSource().get(run, listener); | ||
| assertThat("state", result, is(run.getAbsoluteUrl())); | ||
| } | ||
|
|
||
| } |
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
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.
https://issues.jenkins-ci.org/browse/JENKINS-38611
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.
will fix it in #141 in a few hours