-
Notifications
You must be signed in to change notification settings - Fork 610
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
Add support for Workflows when loading comment files #682
Closed
Closed
Changes from 4 commits
Commits
Show all changes
5 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -11,8 +11,17 @@ | |
import org.jenkinsci.plugins.ghprb.extensions.GhprbExtension; | ||
import org.jenkinsci.plugins.ghprb.extensions.GhprbExtensionDescriptor; | ||
import org.jenkinsci.plugins.ghprb.extensions.GhprbProjectExtension; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowRun; | ||
|
||
import org.jenkinsci.plugins.workflow.graph.FlowGraphWalker; | ||
import org.jenkinsci.plugins.workflow.graph.FlowNode; | ||
import org.jenkinsci.plugins.workflow.graph.BlockStartNode; | ||
import org.jenkinsci.plugins.workflow.flow.FlowExecution; | ||
import org.jenkinsci.plugins.workflow.actions.WorkspaceAction; | ||
|
||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
|
@@ -42,9 +51,50 @@ public String postBuildComment(Run<?, ?> build, TaskListener listener) { | |
|
||
try { | ||
String content = null; | ||
if (build instanceof Build<?, ?>) { | ||
final FilePath workspace = ((Build<?, ?>) build).getWorkspace(); | ||
final FilePath path = workspace.child(scriptFilePathResolved); | ||
FilePath workspace; | ||
FilePath path; | ||
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. looks like these don't need to be declared in the outerscope. it's used within each if block anyway. workspace isn't even used in your if block. |
||
|
||
// On custom pipelines, build will be an instance of WorkflowRun | ||
if (build instanceof WorkflowRun) { | ||
FlowExecution exec = ((WorkflowRun) build).getExecution(); | ||
if (exec == null) { | ||
listener.getLogger().println("build was instanceof WorkflowRun but executor was null"); | ||
} else { | ||
// We walk the execution flow as a run can have multiple workspaces | ||
FlowGraphWalker w = new FlowGraphWalker(exec); | ||
for (FlowNode n : w) { | ||
if (n instanceof BlockStartNode) { | ||
WorkspaceAction action = n.getAction(WorkspaceAction.class); | ||
if (action != null) { | ||
String node = action.getNode().toString(); | ||
String nodepath = action.getPath().toString(); | ||
listener.getLogger().println("Remote path is " + node + ":" + nodepath + "\n"); | ||
|
||
if (action.getWorkspace() == null) { | ||
nosmo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// if the workspace returns null, the workspace either isn't here or it doesn't | ||
// exist - in that case, we fail over to trying to find the comment file locally. | ||
continue; | ||
} | ||
|
||
path = action.getWorkspace().child(scriptFilePathResolved); | ||
|
||
if (path.exists()) { | ||
content = path.readToString(); | ||
} else { | ||
listener.getLogger().println( | ||
"Didn't find comment file in workspace at " + path.absolutize().getRemote() | ||
+ ", falling back to file operations on master.\n" | ||
); | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
} else if (build instanceof Build<?, ?>) { | ||
// When using workers on hosts other than master, we simply get the workspace here. | ||
workspace = ((Build<?, ?>) build).getWorkspace(); | ||
path = workspace.child(scriptFilePathResolved); | ||
|
||
if (path.exists()) { | ||
content = path.readToString(); | ||
|
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.
actually, in the above dsl sample code there is no way to use the comment file. do you know the syntax for this?
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.
Looks like #637 is needed for dsl.
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.
Yeah, it'd be really nice to have this.