From eef680044099551e09d65104e1d43410f17defd5 Mon Sep 17 00:00:00 2001 From: Manon Delahaye Date: Wed, 24 Jan 2024 16:24:24 +0100 Subject: [PATCH 1/3] Add action epic.create using gitlab-python library --- CHANGELOG.md | 5 ++++ README.md | 5 +++- actions/epic_create.py | 32 ++++++++++++++++++++ actions/epic_create.yaml | 40 +++++++++++++++++++++++++ actions/issue_info.py | 2 +- actions/lib/{gitlab.py => gitlabLib.py} | 0 actions/pipeline_list.py | 2 +- actions/pipeline_trigger.py | 2 +- actions/project_info.py | 2 +- pack.yaml | 2 +- requirements.txt | 1 + 11 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 actions/epic_create.py create mode 100644 actions/epic_create.yaml rename actions/lib/{gitlab.py => gitlabLib.py} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9953c8a..90f4357 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v1.1.0 + +* Use of `python-gitlab` library +* New action `epic.create` + ## v1.0.1 * Small bug fixes regarding Python 3 support diff --git a/README.md b/README.md index 4b72898..5778d56 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ verify_ssl: False ## Actions +### Epics + +* `epic.create` - Create new Epic + ### Projects * `project.info` - Returns project information @@ -24,4 +28,3 @@ verify_ssl: False * `pipeline.list` - List all pipelines in a project * `pipeline.trigger` - Create a new pipeline - diff --git a/actions/epic_create.py b/actions/epic_create.py new file mode 100644 index 0000000..183f24f --- /dev/null +++ b/actions/epic_create.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +from st2common.runners.base_action import Action +import gitlab + + +class GitlabEpicCreate(Action): + + # Retrieve config information + def __init__(self, config): + super(GitlabEpicCreate, self).__init__(config=config) + self.url = self.config.get('url') + self.token = self.config.get('token') + + def run(self, group_id, title, labels, description, start_date, due_date, token): + + # Use user token if given + token = token or self.token + + # Initiate GitLab instance + gl = gitlab.Gitlab(self.url, token) + + # Get the group with id == group_id + group = gl.groups.get(group_id) + + # If start/due date is given, tell gitlab it is fixed + due_date_is_fixed = True if due_date else False + start_date_is_fixed = True if start_date else False + + # Create new epic + epic = group.epics.create({'title': title, 'description': description, 'labels': labels, 'start_date_fixed': start_date, 'start_date_is_fixed': start_date_is_fixed, 'due_date_fixed': due_date, 'due_date_is_fixed': due_date_is_fixed}) + return (True, epic) diff --git a/actions/epic_create.yaml b/actions/epic_create.yaml new file mode 100644 index 0000000..01b893f --- /dev/null +++ b/actions/epic_create.yaml @@ -0,0 +1,40 @@ +--- + +name: epic.create +description: "Create new Epic" + +runner_type: python-script +entry_point: epic_create.py + +# Taken from https://docs.gitlab.com/ee/api/epics.html#new-epic +parameters: + group_id: + description: "The ID of the group in which to create the epic" + type: integer + default: 117 + required: true + position: 0 + title: + description: "The title of the epic" + type: string + required: true + position: 1 + labels: + description: "The comma-separated list of labels" + type: string + position: 2 + description: + description: "The description of the epic. Limited to 1,048,576 characters." + type: string + position: 3 + start_date: + description: "The fixed start date of an epic" + type: string + position: 4 + due_date: + description: "The fixed due date of an epic" + type: string + position: 5 + token: + description: "Gitlab token" + type: string diff --git a/actions/issue_info.py b/actions/issue_info.py index 7f386b4..480c055 100755 --- a/actions/issue_info.py +++ b/actions/issue_info.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from lib.gitlab import GitlabIssuesAPI +from lib.gitlabLib import GitlabIssuesAPI class GitlabIssue(GitlabIssuesAPI): diff --git a/actions/lib/gitlab.py b/actions/lib/gitlabLib.py similarity index 100% rename from actions/lib/gitlab.py rename to actions/lib/gitlabLib.py diff --git a/actions/pipeline_list.py b/actions/pipeline_list.py index b44939c..67d8c32 100644 --- a/actions/pipeline_list.py +++ b/actions/pipeline_list.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from lib.gitlab import GitlabPipelineAPI +from lib.gitlabLib import GitlabPipelineAPI class GitlabPipeline(GitlabPipelineAPI): diff --git a/actions/pipeline_trigger.py b/actions/pipeline_trigger.py index decae33..a72e7ab 100644 --- a/actions/pipeline_trigger.py +++ b/actions/pipeline_trigger.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from lib.gitlab import GitlabPipelineAPI +from lib.gitlabLib import GitlabPipelineAPI class GitlabPipelineTrigger(GitlabPipelineAPI): diff --git a/actions/project_info.py b/actions/project_info.py index 53f1cff..ae74d34 100644 --- a/actions/project_info.py +++ b/actions/project_info.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from lib.gitlab import GitlabProjectsAPI +from lib.gitlabLib import GitlabProjectsAPI class GitlabProject(GitlabProjectsAPI): diff --git a/pack.yaml b/pack.yaml index 324c372..96f7284 100644 --- a/pack.yaml +++ b/pack.yaml @@ -3,7 +3,7 @@ name: gitlab description: GitLab Rest API keywords: - gitlab -version: 1.0.1 +version: 1.1.0 author: Daniel Chamot email: daniel@nullkarma.com python_versions: diff --git a/requirements.txt b/requirements.txt index f229360..720b544 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ requests +python-gitlab From 9f79b30e06363337118bf110107bdc56718e4667 Mon Sep 17 00:00:00 2001 From: Manon Delahaye Date: Mon, 29 Jan 2024 19:58:08 +0100 Subject: [PATCH 2/3] Fix - remove default group ID --- CHANGELOG.md | 4 ++++ actions/epic_create.yaml | 1 - pack.yaml | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90f4357..06703fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v1.1.1 + +* Fix - Remove default group id + ## v1.1.0 * Use of `python-gitlab` library diff --git a/actions/epic_create.yaml b/actions/epic_create.yaml index 01b893f..5119ad3 100644 --- a/actions/epic_create.yaml +++ b/actions/epic_create.yaml @@ -11,7 +11,6 @@ parameters: group_id: description: "The ID of the group in which to create the epic" type: integer - default: 117 required: true position: 0 title: diff --git a/pack.yaml b/pack.yaml index 96f7284..bfaeafd 100644 --- a/pack.yaml +++ b/pack.yaml @@ -3,7 +3,7 @@ name: gitlab description: GitLab Rest API keywords: - gitlab -version: 1.1.0 +version: 1.1.1 author: Daniel Chamot email: daniel@nullkarma.com python_versions: From 0fec6d24685b21dbeb459f8f480e17e9de4bcd23 Mon Sep 17 00:00:00 2001 From: Manon Delahaye Date: Fri, 2 Feb 2024 11:26:36 +0100 Subject: [PATCH 3/3] Add action issue.create using gitlab-python library --- CHANGELOG.md | 4 ++++ README.md | 1 + actions/issue_create.py | 30 +++++++++++++++++++++++++ actions/issue_create.yaml | 47 +++++++++++++++++++++++++++++++++++++++ pack.yaml | 2 +- 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 actions/issue_create.py create mode 100644 actions/issue_create.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 06703fa..a1e5bfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v1.1.2 + +* New action `issue.create` + ## v1.1.1 * Fix - Remove default group id diff --git a/README.md b/README.md index 5778d56..3d19c24 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ verify_ssl: False ### Issues * `issue.info` - Returns issue information +* `issue.create` - Create new Issue ### Pipelines diff --git a/actions/issue_create.py b/actions/issue_create.py new file mode 100644 index 0000000..b477642 --- /dev/null +++ b/actions/issue_create.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +from st2common.runners.base_action import Action +import gitlab + + +class GitlabIssueCreate(Action): + + # Retrieve config information + def __init__(self, config): + super(GitlabIssueCreate, self).__init__(config=config) + self.url = self.config.get('url') + self.token = self.config.get('token') + + def run(self, project_id, title, description, assignee_ids, labels, epic_id, due_date, weight, token): + + # Use user token if given + token = token or self.token + + # Initiate GitLab instance + gl = gitlab.Gitlab(self.url, token) + + # Get the project with id == project_id + project = gl.projects.get(project_id) + + # Create new issue + issue = project.issues.create({ 'title': title, 'description': description, 'assignee_ids': assignee_ids, + 'labels': labels, 'epic_id': epic_id, 'due_date': due_date, 'weight': weight}) + + return (True, issue) diff --git a/actions/issue_create.yaml b/actions/issue_create.yaml new file mode 100644 index 0000000..8a4b633 --- /dev/null +++ b/actions/issue_create.yaml @@ -0,0 +1,47 @@ +--- + +name: issue.create +description: "Create new Issue" + +runner_type: python-script +entry_point: issue_create.py + +# Taken from https://docs.gitlab.com/ee/api/issues.html#new-issue +parameters: + project_id: + description: "The ID of the project in which to create the issue" + type: integer + required: true + position: 0 + title: + description: "The title of the issue" + type: string + required: true + position: 1 + description: + description: "The description of the issue" + type: string + position: 2 + assignee_ids: + description: "The comma-separated list of assignee IDs" + type: string + position: 3 + labels: + description: "The comma-separated list of labels" + type: string + position: 4 + epic_id: + description: "The ID of the epic to which the issue should be linked" + type: integer + position: 5 + due_date: + description: "The fixed due date of the issue" + type: string + position: 6 + weight: + description: "The weight of the issue" + type: integer + position: 7 + token: + description: "Gitlab token" + type: string diff --git a/pack.yaml b/pack.yaml index bfaeafd..19d04d7 100644 --- a/pack.yaml +++ b/pack.yaml @@ -3,7 +3,7 @@ name: gitlab description: GitLab Rest API keywords: - gitlab -version: 1.1.1 +version: 1.1.2 author: Daniel Chamot email: daniel@nullkarma.com python_versions: