Skip to content
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: subscribed-scm-notifications should respect the event types and allow PR job of upstream pipeline #3095

Merged
merged 8 commits into from
May 3, 2024

Conversation

VonnyJap
Copy link
Member

@VonnyJap VonnyJap commented Apr 23, 2024

Context

The feature of subscribed-scm-notifications is defective as such that:

  • when a repo is being subscribed by another downstream pipeline, the PR job never start
  • a downstream pipeline is triggered regardless of event types of the upstream repo, for example supposed this is the config
subscribe:
    scmUrls:
        - git@github.com:supra08/functional-workflow.git: ['~pr']
 jobs:
    A:
        steps:
            - echo: echo test
        requires: [~pr, ~commit, ~subscribe]

With the current implementation, job A is triggered even during the commit event of git@github.com:supra08/functional-workflow.git.

Objective

The fix includes:

  • fixing the original SHA of the upstream pipeline that was accidentally overwritten by the subscribed config during the PR events
  • determine the event types of the upstream repo and do a match to the event types that the downstream pipeline is subscribing to

License

I confirm that this contribution is made under a BSD license and that I have the authority necessary to make this contribution on behalf of its copyright owner.

@VonnyJap VonnyJap changed the title fix: fix: subscribed-scm-notifications should respect the event types and allow PR job of upstream pipeline Apr 23, 2024
@coveralls
Copy link

coveralls commented Apr 23, 2024

Coverage Status

coverage: 95.198% (-0.09%) from 95.29%
when pulling b8e2b94 on subscribe
into a20a5fb on master.

p.subscribedScmUrlsWithActions.forEach(subscribedScmUriWithAction => {
const { scmUri: subscribedScmUri, actions: subscribedActions } = subscribedScmUriWithAction;

if (pipelinesOnCommitBranch[0].scmUri === subscribedScmUri) {
Copy link
Contributor

@pritamstyz4ever pritamstyz4ever Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should check length of arr when selecting index

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these lines should be sufficient to ensure that pipelinesOnCommitBranch at least is a length of 1.

if (pipelinesOnCommitBranch.length === 0) {
return currentRepoPipelines;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and I have also added a comment that the subsequent block will only proceed when pipelinesOnCommitBranch is a length of at least 1.

// process the pipelinesWithSubscribedRepos only when the pipelinesOnCommitBranch is not empty
// pipelinesOnCommitBranch has the information to determine the triggering event of downstream subscribing repo

if (uriTrimmer(scmConfig.scmUri) !== uriTrimmer(p.scmUri)) {
subscribedConfigSha = sha;

try {
sha = await pipelineFactory.scm.getCommitSha({
configPipelineSha = await pipelineFactory.scm.getCommitSha({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configPipelineSha is not defined

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is initialized

let configPipelineSha = '';

Comment on lines +367 to +380
if (pipelinesOnCommitBranch.length === 0) {
return currentRepoPipelines;
}

// process the pipelinesWithSubscribedRepos only when the pipelinesOnCommitBranch is not empty
// pipelinesOnCommitBranch has the information to determine the triggering event of downstream subscribing repo
pipelinesWithSubscribedRepos.forEach(p => {
if (!Array.isArray(p.subscribedScmUrlsWithActions)) {
return;
}
p.subscribedScmUrlsWithActions.forEach(subscribedScmUriWithAction => {
const { scmUri: subscribedScmUri, actions: subscribedActions } = subscribedScmUriWithAction;

if (pipelinesOnCommitBranch[0].scmUri === subscribedScmUri) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could probably refactor the loops into a function and return the filteredPipelines

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think as it stands, there is no reusable purpose for this section that can bring a benefit of putting into a function. So I would propose to keep it as is.

Copy link
Contributor

@pritamstyz4ever pritamstyz4ever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments

@VonnyJap
Copy link
Member Author

VonnyJap commented May 2, 2024

@pritamstyz4ever - responded to your comments.

branch: Promise.resolve('master')
})
]);
const pipelineMock2 = _.cloneDeep(pipelineMock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can write a simple deep clone instead of adding the entire lodash pkg I think

@@ -93,6 +93,7 @@
"js-yaml": "^3.14.1",
"jsonwebtoken": "^9.0.0",
"license-checker": "^25.0.1",
"lodash": "^4.17.21",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used only in tests, move to dev-dependencies

@VonnyJap VonnyJap merged commit 0782760 into master May 3, 2024
2 checks passed
@VonnyJap VonnyJap deleted the subscribe branch May 3, 2024 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants