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(2437): Add method to get read-only flag [2] #87

Merged
merged 9 commits into from
Jun 11, 2021
Merged

Conversation

tkyi
Copy link
Member

@tkyi tkyi commented May 13, 2021

Context

We need to get data from the SCM config: read-only flag, scmContext.

Objective

This PR:

  • adds getReadOnlyInfo() method to return read-only SCM config
  • adds getConfig() method to inject read-only token if read-only enabled
  • adds getScmContext() method to get scmContext based on hostname
  • adds/fixes tests for getWebhooksEventsMapping()

References

Related to screwdriver-cd/screwdriver#2437

License

I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.

index.js Outdated
/**
* Set token correctly if is read-only SCM
* @param {Object} config
* @param {String} [token] SCM token
Copy link
Contributor

Choose a reason for hiding this comment

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

extra param declaration

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

index.js Outdated
*/
getConfig(config) {
const newConfig = config;
const readOnlyToken = Hoek.reach(this.config, 'readOnly.accessToken');
Copy link
Contributor

Choose a reason for hiding this comment

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

can we fetch the readonly config


if (newConfig && readOnlyConfig.enabled && readOnlyConfig.accessToken) {

index.js Outdated
*/
getConfig(config) {
const newConfig = config;
const readOnlyToken = Hoek.reach(this.config, 'readOnly.accessToken');
Copy link
Member

Choose a reason for hiding this comment

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

config already contains a username & commentUserToken. Is this newly added readOnly access token end up being same as commentUserToken ? Should we have just one token ?

Copy link
Member Author

Choose a reason for hiding this comment

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

So here are my thoughts about that:

  • ideally it'd be nice to have just one token but the commentUserToken is supposed to be strictly used for PR comments
  • if we want to overload it, I can change this; might cause breaking changes?
  • also having a separate username is nice so that it's clear that everything in that section is for readOnly purpose, like this:
scms:
  gitlab:
    username: username
    commentUserToken: commentToken
    readOnly:
      enabled: true
      username: readOnlyUsername
      accessToken: readOnlyToken

If you want just one of everything, could have something like this:

scms:
  gitlab:
    username: username
    commentUserToken: token
    readOnlyEnabled: true

@@ -4,6 +4,11 @@
const assert = require('chai').assert;
const token = 'token';
const testParseHook = require('./data/parseHookOutput.json');
const readOnlyConfig = {
enabled: true,
username: 'headlessbot',
Copy link
Member

Choose a reason for hiding this comment

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

in practice will this user end up same as "sd-buildbot" ? If so should we reuse the user refined in scm config section

@tkyi tkyi merged commit 559cbb4 into master Jun 11, 2021
@tkyi tkyi deleted the readOnlyScm branch June 11, 2021 21:04
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