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

feat(1769): [5] Add processHooks endpoint for queue-service cooperation #2622

Merged

Conversation

yk634
Copy link
Contributor

@yk634 yk634 commented Dec 20, 2021

Context

We implemented a worker that retrieves a queue and requests the API last time.
I add an endpoint that will receive the webhookConfig sent by the worker.

The scope of this PR is to implement commonly referenced helpers.
The process of calling the quese-service API will be implemented in another context.

Objective

  • Add an endpoint /processHooks that receives the webhookConfig sent by the worker and starts the event.
  • The parts that share processing with /webhooks are shared as helper.
  • Some of the tests done by the webhooks plugin have been moved to helper tests.
    • We should migrate most of the tests run at the webhooks plugin to the helper, but in this PR we have only migrated the tests that are easy to migrate. The rest of the migration will be handled in another context.
    • There is no change in the tests run, so the all necessary test cases will still be run.

References

Please do not merge this PR until after the following PRs have been merged.

#1769 (comment)

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.

@coveralls
Copy link

coveralls commented Dec 20, 2021

Coverage Status

Coverage decreased (-0.08%) to 95.482% when pulling 6280e07 on sonic-screwdriver-cd:use-queueservice-for-webhook into 2f0f5d9 on screwdriver-cd:master.

@yk634 yk634 changed the title [WIP] feat(1769): [4] Add processHooks endpoint for queue-service cooperation feat(1769): [4] Add processHooks endpoint for queue-service cooperation Dec 20, 2021
@yoshwata
Copy link
Contributor

If you change the key name of payload, the getChangedFiles is also need to be changed.

scm.getChangedFiles({

const joi = require('joi');
const { startHookEvent } = require('../webhooks/helper');

const DEFAULT_MAX_BYTES = 1048576;
Copy link
Member

Choose a reason for hiding this comment

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

is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not used. I removed them.

plugins/processHooks/index.js Outdated Show resolved Hide resolved
// disregard skip ci for pull request events
return pullRequestEvent(pluginOptions, request, h, parsed, token);
}
return await startHookEvent(pluginOptions, request, h, parsed);
Copy link
Member

Choose a reason for hiding this comment

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

I don't know well about scope of this PR. Can we start event directly instead of calling queue service API when /webhook is called?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. The scope of this PR is to implement commonly referenced helpers.
The process of calling the quese-service API will be implemented in another context.

@yk634 yk634 changed the title feat(1769): [4] Add processHooks endpoint for queue-service cooperation feat(1769): [5] Add processHooks endpoint for queue-service cooperation Dec 21, 2021
// disregard skip ci for pull request events
return pullRequestEvent(pluginOptions, request, h, parsed, token);
}
return await startHookEvent(pluginOptions, request, h, parsed);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since pluginOptions is stored in parsed.pluginOptions, shouldn't 3 arguments, request, h, parsed, be enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed it.

itleigns
itleigns previously approved these changes Dec 21, 2021
* @method startHookEvent
* @param {Hapi.request} request Request from user
* @param {Object} h Response toolkit
* @param {Object} webhookConfig Parsed request.payload by scm webhook
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it store pluginOptions as well as request.payload?
In the requestHook API, it's not passing webhookConfig.pluginOptions as an argument, is that ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I fixed the documentation of startHookEvent.

Copy link
Member

@tk3fftk tk3fftk left a comment

Choose a reason for hiding this comment

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

I think we should add and migrate some test for helper.js from webhooks.test.js because this PR separates function and another PR will make some current webhooks test outdated.

}

/**
* Start pipeline events from scm webhook config
Copy link
Member

Choose a reason for hiding this comment

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

same here but I don't know the same is correct.

Suggested change
* Start pipeline events from scm webhook config
* Start pipeline events with scm webhook config via queue-service

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed it.
Since this function is not necessarily called via queue-service, the phrase via queue-service has been omitted.

scmUri = await scm.parseUrl({ checkoutUrl, token, scmContext });
}
webhookConfig.changedFiles = await scm.getChangedFiles({
webhookConfig,
Copy link
Member

Choose a reason for hiding this comment

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

this might not be able to omit because the name is different.

Suggested change
webhookConfig,
payload: webhookConfig,

Copy link
Member

Choose a reason for hiding this comment

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

and does webhookConfig contain request.payload?

Copy link
Contributor Author

@yk634 yk634 Dec 21, 2021

Choose a reason for hiding this comment

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

The argument of getChangedFiles will turn into webhookConfig at this PR.

Copy link
Member

Choose a reason for hiding this comment

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

make sense


if (type === 'pr') {
// disregard skip ci for pull request events
return pullRequestEvent(webhookConfig.pluginOptions, request, h, webhookConfig, token);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return pullRequestEvent(webhookConfig.pluginOptions, request, h, webhookConfig, token);
return pullRequestEvent(pluginOptions: webhookConfig.pluginOptions, request, h, webhookConfig, token);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the argument of this function is not an object literal, it should be left as it is.

wahapo
wahapo previously approved these changes Dec 21, 2021
tk3fftk
tk3fftk previously approved these changes Dec 22, 2021
@yk634 yk634 changed the title feat(1769): [5] Add processHooks endpoint for queue-service cooperation [DNM] feat(1769): [5] Add processHooks endpoint for queue-service cooperation Dec 22, 2021
@yk634 yk634 changed the title [DNM] feat(1769): [5] Add processHooks endpoint for queue-service cooperation feat(1769): [5] Add processHooks endpoint for queue-service cooperation Dec 22, 2021
@yk634
Copy link
Contributor Author

yk634 commented Dec 23, 2021

In addition, some of the tests run by the webhooks plugin have been moved to helper tests.

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.

9 participants