-
Couldn't load subscription status.
- Fork 90
Use CI JOB TOKEN to push code #901
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
base: master
Are you sure you want to change the base?
Changes from all commits
542a2eb
cd1e41a
c007a95
9ab63f1
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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import AggregateError from "aggregate-error"; | |
| import resolveConfig from "./resolve-config.js"; | ||
| import getProjectContext from "./get-project-context.js"; | ||
| import getError from "./get-error.js"; | ||
| import urlJoin from "url-join"; | ||
|
|
||
| const isNonEmptyString = (value) => isString(value) && value.trim(); | ||
| const isStringOrStringArray = (value) => | ||
|
|
@@ -30,7 +31,17 @@ export default async (pluginConfig, context) => { | |
| options: { repositoryUrl }, | ||
| logger, | ||
| } = context; | ||
| const { gitlabToken, gitlabUrl, gitlabApiUrl, proxy, ...options } = resolveConfig(pluginConfig, context); | ||
| const { | ||
| gitlabToken, | ||
| isJobToken, | ||
| tokenHeader, | ||
| successCommentCondition, | ||
| failCommentCondition, | ||
| gitlabUrl, | ||
| gitlabApiUrl, | ||
| proxy, | ||
| ...options | ||
| } = resolveConfig(pluginConfig, context); | ||
| const { projectPath, projectApiUrl } = getProjectContext(context, gitlabUrl, gitlabApiUrl, repositoryUrl); | ||
|
|
||
| debug("apiUrl: %o", gitlabApiUrl); | ||
|
|
@@ -53,30 +64,38 @@ export default async (pluginConfig, context) => { | |
| errors.push(getError("ENOGLTOKEN", { repositoryUrl })); | ||
| } | ||
|
|
||
| if (isJobToken && !(failCommentCondition === false) && !(successCommentCondition === false)) { | ||
| errors.push(getError("EJOBTOKENCOMMENTCONDITION", { projectPath })); | ||
| } | ||
|
|
||
| if (gitlabToken && projectPath) { | ||
| let projectAccess; | ||
| let groupAccess; | ||
|
|
||
| logger.log("Verify GitLab authentication (%s)", gitlabApiUrl); | ||
|
|
||
| try { | ||
| ({ | ||
| permissions: { project_access: projectAccess, group_access: groupAccess }, | ||
| } = await got | ||
| .get(projectApiUrl, { | ||
| headers: { "PRIVATE-TOKEN": gitlabToken }, | ||
| ...proxy, | ||
| }) | ||
| .json()); | ||
| if ( | ||
| context.options.dryRun && | ||
| !((projectAccess && projectAccess.access_level >= 10) || (groupAccess && groupAccess.access_level >= 10)) | ||
| ) { | ||
| errors.push(getError("EGLNOPULLPERMISSION", { projectPath })); | ||
| } else if ( | ||
| !((projectAccess && projectAccess.access_level >= 30) || (groupAccess && groupAccess.access_level >= 30)) | ||
| ) { | ||
| errors.push(getError("EGLNOPUSHPERMISSION", { projectPath })); | ||
| if (isJobToken) { | ||
| await got.get(urlJoin(projectApiUrl, "releases"), { headers: { [tokenHeader]: gitlabToken } }); | ||
|
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 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. @fgreinacher I don't think we have one at the moment, The only reliable way I know at the moment is dry run of |
||
| } else { | ||
| ({ | ||
| permissions: { project_access: projectAccess, group_access: groupAccess }, | ||
| } = await got | ||
| .get(projectApiUrl, { | ||
| headers: { [tokenHeader]: gitlabToken }, | ||
| ...proxy, | ||
| }) | ||
| .json()); | ||
| if ( | ||
| context.options.dryRun && | ||
| !((projectAccess && projectAccess.access_level >= 10) || (groupAccess && groupAccess.access_level >= 10)) | ||
| ) { | ||
| errors.push(getError("EGLNOPULLPERMISSION", { projectPath })); | ||
| } else if ( | ||
| !((projectAccess && projectAccess.access_level >= 30) || (groupAccess && groupAccess.access_level >= 30)) | ||
| ) { | ||
| errors.push(getError("EGLNOPUSHPERMISSION", { projectPath })); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| if (error.response && error.response.statusCode === 401) { | ||
|
|
||
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.
There's an inconsistency in casing - the error message references 'successCommentCondition' and 'failCommentCondition' but the actual configuration options are 'successCommentCondition' and 'failCommentCondition'. Based on the test code, the correct names should be 'successCommentCondition' and 'failCommentCondition'.