From 6e3de43a425ff42bdcf543fb5500249bb172f924 Mon Sep 17 00:00:00 2001 From: Manon Delahaye Date: Fri, 2 Feb 2024 11:26:36 +0100 Subject: [PATCH] Add issue.create action --- actions/issue_create.py | 30 +++++++++++++++++++++++++ actions/issue_create.yaml | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 actions/issue_create.py create mode 100644 actions/issue_create.yaml 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