-
Notifications
You must be signed in to change notification settings - Fork 354
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
[JENKINS-55927] Hook event should not trigger Branch Indexing #908
base: master
Are you sure you want to change the base?
Changes from 4 commits
0018451
5321736
89eaa77
e745215
d91fb40
101d3b5
2fb95c7
756bb42
5f842ac
78f8552
a35cfac
796da9a
ba8c034
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 |
---|---|---|
|
@@ -39,8 +39,7 @@ | |
* Abstract hook processor. | ||
* | ||
* Add new hook processors by extending this class and implement {@link #process(HookEventType, String, BitbucketType, String)}, | ||
* extract owner and repository name from the hook payload and then call {@link #scmSourceReIndex(String, String)} | ||
* to launch a branch/PR reindexing on the matching SCMSource. | ||
* extract details from the hook payload and then fire an {@link jenkins.scm.api.SCMEvent} to dispatch it to the SCM API. | ||
*/ | ||
public abstract class HookProcessor { | ||
|
||
|
@@ -86,10 +85,11 @@ | |
/** | ||
* To be called by implementations once the owner and the repository have been extracted from the payload. | ||
* | ||
* @deprecated SCM Event should not trigger Branch Indexing | ||
* @param owner the repository owner as configured in the SCMSource | ||
* @param repository the repository name as configured in the SCMSource | ||
*/ | ||
protected void scmSourceReIndex(final String owner, final String repository) { | ||
Check warning on line 92 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/HookProcessor.java ci.jenkins.io / Java Compilercompiler:compile
|
||
try (ACLContext context = ACL.as(ACL.SYSTEM)) { | ||
boolean reindexed = false; | ||
for (SCMSourceOwner scmOwner : SCMSourceOwners.all()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,27 +59,30 @@ | |
|
||
public class PushHookProcessor extends HookProcessor { | ||
|
||
private static final boolean SCAN_ON_PUSH_WITH_EMPTY_CHANGES = Boolean.getBoolean( | ||
PushHookProcessor.class.getName()+".scanOnPushWithEmptyChanges"); | ||
|
||
private static final Logger LOGGER = Logger.getLogger(PushHookProcessor.class.getName()); | ||
|
||
@Override | ||
public void process(HookEventType hookEvent, String payload, BitbucketType instanceType, String origin) { | ||
if (payload != null) { | ||
BitbucketPushEvent push; | ||
if (instanceType == BitbucketType.SERVER) { | ||
push = BitbucketServerWebhookPayload.pushEventFromPayload(payload); | ||
} else { | ||
push = BitbucketCloudWebhookPayload.pushEventFromPayload(payload); | ||
} | ||
if (push != null) { | ||
String owner = push.getRepository().getOwnerName(); | ||
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. As described in JIRA issue I think these changes will cause to the user that have setup "Discover pull requests" strategies different than "The current pull request revision" they never get a build for PRs which target branch is the same branch subject of the merged. 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. The JIRA mentions the |
||
final String repository = push.getRepository().getRepositoryName(); | ||
if (push.getChanges().isEmpty()) { | ||
LOGGER.log(Level.INFO, "Received hook from Bitbucket. Processing push event on {0}/{1}", | ||
new Object[]{owner, repository}); | ||
if (SCAN_ON_PUSH_WITH_EMPTY_CHANGES && push.getChanges().isEmpty()) { | ||
final String owner = push.getRepository().getOwnerName(); | ||
final String repository = push.getRepository().getRepositoryName(); | ||
LOGGER.log(Level.INFO, "Received push hook with empty changes from Bitbucket. Processing push event on {0}/{1}", | ||
new Object[]{owner, repository}); | ||
|
||
scmSourceReIndex(owner, repository); | ||
} else { | ||
SCMHeadEvent.Type type = null; | ||
for (BitbucketPushEvent.Change change: push.getChanges()) { | ||
for (BitbucketPushEvent.Change change : push.getChanges()) { | ||
if ((type == null || type == SCMEvent.Type.CREATED) && change.isCreated()) { | ||
type = SCMEvent.Type.CREATED; | ||
} else if ((type == null || type == SCMEvent.Type.REMOVED) && change.isClosed()) { | ||
|
@@ -170,7 +173,7 @@ | |
} | ||
|
||
Map<SCMHead, SCMRevision> result = new HashMap<>(); | ||
for (BitbucketPushEvent.Change change: getPayload().getChanges()) { | ||
for (BitbucketPushEvent.Change change : getPayload().getChanges()) { | ||
if (change.isClosed()) { | ||
result.put(new BranchSCMHead(change.getOld().getName()), null); | ||
} else { | ||
|
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.
it's not possible, this will have a worster impact on issues like #539
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.
The impact really depend on a the environment. User that have large repositories with hundreds of branches / PRs cannot afford frequent branch indexing.
In case of #539, branch indexing is not a good solution IMO. A pull request decline event should not trigger branch indexing, but rather update the source and target based on discovery criteria through
SCMHeadEvent
s.Maybe the description could be improved.
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.
This is hard because you should apply any registered trait (also external to this plugin) and simulate if any existing job is related to the target branch and in case delete or create.
In master I start to add unit test collecting some bitbucket cloud events and I'm providing test on how I expect they should do