-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fix tfs push bug #1
Changes from 7 commits
c4a2399
83fb492
c345498
38d1c0f
83fdbb0
45b2fd4
959dc21
7d6d684
cfd55e1
5021220
447d380
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,68 @@ static JSONObject fromResponseContributors(final List<GitStatus.ResponseContribu | |
return result; | ||
} | ||
|
||
GitStatus.ResponseContributor triggerJob(final GitCodePushedEventArgs gitCodePushedEventArgs, final List<Action> actions, final boolean bypassPolling, final Item project, final SCMTriggerItem scmTriggerItem) { | ||
GitStatus.ResponseContributor gitResponse = null; | ||
|
||
if (!(project instanceof AbstractProject && ((AbstractProject) project).isDisabled())) { | ||
if (project instanceof Job) { | ||
// TODO: Add default parameters defined in the job | ||
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. Is it really not queueing it with parameters? 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. Verified the jobs being kicked off do use customized params, so this comment isn't needed any more, removed it. |
||
final Job job = (Job) project; | ||
final int quietPeriod = scmTriggerItem.getQuietPeriod(); | ||
|
||
boolean triggered = false; | ||
if (!triggered) { | ||
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. This is always false here 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. Yep, this is the code from original plugin. I've removed this unnecessary if statement. |
||
final TeamPluginGlobalConfig config = TeamPluginGlobalConfig.get(); | ||
if (config.isEnableTeamPushTriggerForAllJobs()) { | ||
triggered = true; | ||
final SCMTrigger scmTrigger = TeamEventsEndpoint.findTrigger(job, SCMTrigger.class); | ||
if (scmTrigger != null && scmTrigger.isIgnorePostCommitHooks()) { | ||
// job has explicitly opted out of hooks | ||
triggered = false; | ||
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. There is a lot of use of triggered in here in sort of confusing ways. I think the if (triggered) block below should be inlined into this block (invert the above if condition), returning the new gitResponse directly rather than waiting for the end of the series of if statements. 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. Refined the logic, and removed "triggered" var entirely as it becomes unnecessary. Also changed to return directly instead of waiting. |
||
} | ||
} | ||
if (triggered) { | ||
final TeamPushTrigger trigger = new TeamPushTrigger(job); | ||
trigger.execute(gitCodePushedEventArgs, actions, bypassPolling); | ||
if (bypassPolling) { | ||
gitResponse = new TeamEventsEndpoint.ScheduledResponseContributor(project); | ||
} | ||
else { | ||
gitResponse = new TeamEventsEndpoint.PollingScheduledResponseContributor(project); | ||
} | ||
} | ||
} | ||
if (!triggered) { | ||
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. If you inline the if (triggered) block, then this if (!triggered) becomes unnecessary since it's always false if you get here. 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. Yep, removed "triggered" var entirely as it becomes unnecessary. |
||
final SCMTrigger scmTrigger = TeamEventsEndpoint.findTrigger(job, SCMTrigger.class); | ||
if (scmTrigger != null && !scmTrigger.isIgnorePostCommitHooks()) { | ||
// queue build without first polling | ||
final Cause cause = new TeamHookCause(gitCodePushedEventArgs.commit); | ||
final CauseAction causeAction = new CauseAction(cause); | ||
final Action[] actionArray = ActionHelper.create(actions, causeAction); | ||
scmTriggerItem.scheduleBuild2(quietPeriod, actionArray); | ||
gitResponse = new TeamEventsEndpoint.ScheduledResponseContributor(project); | ||
triggered = true; | ||
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. Again you could just return gitResponse directly from this block 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. Good suggestion, did that. |
||
} | ||
} | ||
if (!triggered) { | ||
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. Which would make this always false again. 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. Agree, removed this unnecessary statement. |
||
final TeamPushTrigger pushTrigger = TeamEventsEndpoint.findTrigger(job, TeamPushTrigger.class); | ||
if (pushTrigger != null) { | ||
pushTrigger.execute(gitCodePushedEventArgs, actions, bypassPolling); | ||
final GitStatus.ResponseContributor response; | ||
if (bypassPolling) { | ||
gitResponse = new TeamEventsEndpoint.ScheduledResponseContributor(project); | ||
} | ||
else { | ||
gitResponse = new TeamEventsEndpoint.PollingScheduledResponseContributor(project); | ||
} | ||
triggered = true; | ||
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. And again return directly from this 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. Done. |
||
} | ||
} | ||
} | ||
} | ||
return gitResponse; | ||
} | ||
|
||
// TODO: it would be easiest if pollOrQueueFromEvent built a JSONObject directly | ||
List<GitStatus.ResponseContributor> pollOrQueueFromEvent(final GitCodePushedEventArgs gitCodePushedEventArgs, final List<Action> actions, final boolean bypassPolling) { | ||
List<GitStatus.ResponseContributor> result = new ArrayList<GitStatus.ResponseContributor>(); | ||
|
@@ -111,90 +173,10 @@ List<GitStatus.ResponseContributor> pollOrQueueFromEvent(final GitCodePushedEven | |
if (scmTriggerItem == null) { | ||
continue; | ||
} | ||
for (final SCM scm : scmTriggerItem.getSCMs()) { | ||
if (!(scm instanceof GitSCM)) { | ||
continue; | ||
} | ||
final GitSCM git = (GitSCM) scm; | ||
scmFound = true; | ||
|
||
for (final RemoteConfig repository : git.getRepositories()) { | ||
boolean repositoryMatches = false; | ||
for (final URIish remoteURL : repository.getURIs()) { | ||
if (UriHelper.areSameGitRepo(uri, remoteURL)) { | ||
repositoryMatches = true; | ||
totalRepositoryMatches++; | ||
break; | ||
} | ||
} | ||
|
||
if (!repositoryMatches || git.getExtensions().get(IgnoreNotifyCommit.class)!=null) { | ||
continue; | ||
} | ||
|
||
if (!(project instanceof AbstractProject && ((AbstractProject) project).isDisabled())) { | ||
if (project instanceof Job) { | ||
// TODO: Add default parameters defined in the job | ||
final Job job = (Job) project; | ||
final int quietPeriod = scmTriggerItem.getQuietPeriod(); | ||
|
||
boolean triggered = false; | ||
if (!triggered) { | ||
final TeamPluginGlobalConfig config = TeamPluginGlobalConfig.get(); | ||
if (config.isEnableTeamPushTriggerForAllJobs()) { | ||
triggered = true; | ||
final SCMTrigger scmTrigger = TeamEventsEndpoint.findTrigger(job, SCMTrigger.class); | ||
if (scmTrigger != null && scmTrigger.isIgnorePostCommitHooks()) { | ||
// job has explicitly opted out of hooks | ||
triggered = false; | ||
} | ||
} | ||
if (triggered) { | ||
final TeamPushTrigger trigger = new TeamPushTrigger(job); | ||
trigger.execute(gitCodePushedEventArgs, actions, bypassPolling); | ||
final GitStatus.ResponseContributor response; | ||
if (bypassPolling) { | ||
response = new TeamEventsEndpoint.ScheduledResponseContributor(project); | ||
} | ||
else { | ||
response = new TeamEventsEndpoint.PollingScheduledResponseContributor(project); | ||
} | ||
result.add(response); | ||
} | ||
} | ||
if (!triggered) { | ||
final SCMTrigger scmTrigger = TeamEventsEndpoint.findTrigger(job, SCMTrigger.class); | ||
if (scmTrigger != null && !scmTrigger.isIgnorePostCommitHooks()) { | ||
// queue build without first polling | ||
final Cause cause = new TeamHookCause(commit); | ||
final CauseAction causeAction = new CauseAction(cause); | ||
final Action[] actionArray = ActionHelper.create(actions, causeAction); | ||
scmTriggerItem.scheduleBuild2(quietPeriod, actionArray); | ||
result.add(new TeamEventsEndpoint.ScheduledResponseContributor(project)); | ||
triggered = true; | ||
} | ||
} | ||
if (!triggered) { | ||
final TeamPushTrigger pushTrigger = TeamEventsEndpoint.findTrigger(job, TeamPushTrigger.class); | ||
if (pushTrigger != null) { | ||
pushTrigger.execute(gitCodePushedEventArgs, actions, bypassPolling); | ||
final GitStatus.ResponseContributor response; | ||
if (bypassPolling) { | ||
response = new TeamEventsEndpoint.ScheduledResponseContributor(project); | ||
} | ||
else { | ||
response = new TeamEventsEndpoint.PollingScheduledResponseContributor(project); | ||
} | ||
result.add(response); | ||
triggered = true; | ||
} | ||
} | ||
if (triggered) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
GitStatus.ResponseContributor triggerResult = triggerJob(gitCodePushedEventArgs, actions, bypassPolling, project, scmTriggerItem); | ||
if (triggerResult != null) { | ||
result.add(triggerResult); | ||
} | ||
} | ||
if (!scmFound) { | ||
|
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.
I would prefer...
|| StringUtils.isNotBlank(gitCodePushedEventArgs.commit)
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.
Good suggestion Jason, I'll fix and verify it.