Skip to content
Snippets Groups Projects
Verified Commit 82fb5608 authored by Newbyte's avatar Newbyte :snowflake:
Browse files

mrhlpr: Link documentation for how to set up personal access token on error

Previously you'd just get an error that GITLAB_TOKEN wasn't set in the
environment without any information about how to resolve this.
parent 68f84cae
No related branches found
No related tags found
1 merge request!37mrhlpr: Link documentation for how to set up personal access token on error
Pipeline #185107 passed
......@@ -449,6 +449,14 @@ def finish(mr_id: int, comment: str | None, no_cache: bool = False):
logging.error("python-gitlab is needed to run 'finish'")
exit(1)
gitlab_token = os.environ.get("GITLAB_TOKEN")
if not gitlab_token:
logging.error(
"To use 'finish' you need a personal access token set in the environment as GITLAB_TOKEN. See https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html."
)
exit(1)
print("Pushing changes...")
status = get_status(mr_id, no_cache)
origin = gitlab.parse_git_origin()
......@@ -457,7 +465,7 @@ def finish(mr_id: int, comment: str | None, no_cache: bool = False):
remote_local = "origin"
git.push_head(remote_local, status.source_branch)
gl = gitlab_api.Gitlab(url="https://gitlab.com", private_token=os.environ["GITLAB_TOKEN"])
gl = gitlab_api.Gitlab(url="https://gitlab.com", private_token=gitlab_token)
project = gl.projects.get(origin.project_id)
mr = project.mergerequests.get(mr_id)
print("Approving MR...")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment