-
Notifications
You must be signed in to change notification settings - Fork 23
[gitlab] Add GitLab connection and EventInfo classes #370
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
Open
sondrebr
wants to merge
19
commits into
EESSI:gitlab
Choose a base branch
from
sondrebr:add-gitlab-support-event-info-classes
base: gitlab
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4a3aa49
Update requirements for GitLab support
sondrebr b74d264
Add Git and GitLab config sections
sondrebr 61790e1
Connect event handler to GitLab if configured
sondrebr 776ed15
Add optional cfg parameter to get_hosting_platform
sondrebr a99faaa
Add docstring to connect_to_host
sondrebr d293629
Update PyGHee requirement
sondrebr 1f5011b
Add tools/event_info.py
sondrebr 22bfaed
Make event handler use EventInfo classes
sondrebr c06b98d
Update app.cfg.example to add git, gitlab sections
sondrebr ab02d4d
Pin python-gitlab
sondrebr 5e5259f
Prevent overriding `BaseEventInfo.__getitem__`
sondrebr 9e7f6eb
Use more descriptive names in tools/git.py
sondrebr 611022a
Add a few clarifying comments
sondrebr 4155c30
`Gitlab` refers to a class in `python-gitlab`
sondrebr 91c4860
Remove EventInfo.discussion_id
sondrebr f8391b0
Implement GitLabEventInfo.label_name
sondrebr 8502631
Add issue_number and issue_url properties
sondrebr 6996b9e
Rename comment_updated_by to event_triggered_by
sondrebr 373e6db
Add fallback to `create_event_info_instance`
sondrebr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # This file is part of the EESSI build-and-deploy bot, | ||
| # see https://github.com/EESSI/eessi-bot-software-layer | ||
| # | ||
| # The bot helps with requests to add software installations to the | ||
| # EESSI software layer, see https://github.com/EESSI/software-layer | ||
| # | ||
| # author: Sondre Bergsvaag Risanger (@sondrebr) | ||
| # | ||
| # license: GPLv2 | ||
| # | ||
|
|
||
| # Standard library imports | ||
| import os | ||
|
|
||
| # Third party imports (anything installed into the local Python environment) | ||
| import gitlab | ||
|
|
||
| # Local application imports (anything from EESSI/eessi-bot-software-layer) | ||
| from tools import config, logging | ||
|
|
||
|
|
||
| _gl = None | ||
|
|
||
|
|
||
| def verify_connection(gl): | ||
| """ | ||
| Verifies connection to GitLab. Exits if verification fails. | ||
|
|
||
| Args: | ||
| Instance of gitlab.Gitlab (from python-gitlab) | ||
|
|
||
| Returns: | ||
| None (implicit) | ||
| """ | ||
| try: | ||
| # auth tests the instance's credentials by retrieving the access token user | ||
| gl.auth() | ||
| if type(gl.user) is not gl._objects.CurrentUser: | ||
| raise Exception("'user' attribute of Gitlab class instance is not of type 'CurrentUser'.") | ||
| except Exception as err: | ||
| logging.error(f"Failed to verify GitLab connection: {err}") | ||
|
|
||
|
|
||
| def connect(): | ||
| """ | ||
| Creates a gitlab.Gitlab instance (from python-gitlab), then verifies the connection to GitLab. | ||
|
|
||
| Args: | ||
| No arguments | ||
|
|
||
| Returns: | ||
| None (implicit) | ||
| """ | ||
| global _gl | ||
| cfg = config.read_config() | ||
| gitlab_cfg = cfg[config.SECTION_GITLAB] | ||
| timeout = int(gitlab_cfg.get(config.GITLAB_SETTING_API_TIMEOUT, 10)) | ||
| url = gitlab_cfg.get(config.GITLAB_SETTING_INSTANCE_URL) | ||
|
|
||
| access_token = os.getenv('GITLAB_PROJECT_ACCESS_TOKEN') | ||
| if access_token is None: | ||
| logging.error("GitLab token is not available via $GITLAB_PROJECT_ACCESS_TOKEN!") | ||
| else: | ||
| del os.environ['GITLAB_PROJECT_ACCESS_TOKEN'] | ||
|
|
||
| _gl = gitlab.Gitlab(url, access_token) | ||
| _gl.timeout = timeout | ||
| _gl.retry_transient_errors = True | ||
| verify_connection(_gl) | ||
|
|
||
|
|
||
| def get_instance(): | ||
| """ | ||
| Returns a gitlab.Gitlab instance. Creates an instance if one does not exist, | ||
| otherwise verifies the existing instance. | ||
|
|
||
| Args: | ||
| No arguments | ||
|
|
||
| Returns: | ||
| Instance of gitlab.Gitlab (from python-gitlab) | ||
| """ | ||
| if not _gl: | ||
| connect() | ||
| else: | ||
| verify_connection(_gl) | ||
| return _gl | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.