Skip to content

Commit 0fec6d2

Browse files
author
Manon Delahaye
committed
Add action issue.create using gitlab-python library
1 parent 9f79b30 commit 0fec6d2

File tree

5 files changed

+83
-1
lines changed

5 files changed

+83
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v1.1.2
2+
3+
* New action `issue.create`
4+
15
## v1.1.1
26

37
* Fix - Remove default group id

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ verify_ssl: False
2323
### Issues
2424

2525
* `issue.info` - Returns issue information
26+
* `issue.create` - Create new Issue
2627

2728
### Pipelines
2829

actions/issue_create.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
3+
from st2common.runners.base_action import Action
4+
import gitlab
5+
6+
7+
class GitlabIssueCreate(Action):
8+
9+
# Retrieve config information
10+
def __init__(self, config):
11+
super(GitlabIssueCreate, self).__init__(config=config)
12+
self.url = self.config.get('url')
13+
self.token = self.config.get('token')
14+
15+
def run(self, project_id, title, description, assignee_ids, labels, epic_id, due_date, weight, token):
16+
17+
# Use user token if given
18+
token = token or self.token
19+
20+
# Initiate GitLab instance
21+
gl = gitlab.Gitlab(self.url, token)
22+
23+
# Get the project with id == project_id
24+
project = gl.projects.get(project_id)
25+
26+
# Create new issue
27+
issue = project.issues.create({ 'title': title, 'description': description, 'assignee_ids': assignee_ids,
28+
'labels': labels, 'epic_id': epic_id, 'due_date': due_date, 'weight': weight})
29+
30+
return (True, issue)

actions/issue_create.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
3+
name: issue.create
4+
description: "Create new Issue"
5+
6+
runner_type: python-script
7+
entry_point: issue_create.py
8+
9+
# Taken from https://docs.gitlab.com/ee/api/issues.html#new-issue
10+
parameters:
11+
project_id:
12+
description: "The ID of the project in which to create the issue"
13+
type: integer
14+
required: true
15+
position: 0
16+
title:
17+
description: "The title of the issue"
18+
type: string
19+
required: true
20+
position: 1
21+
description:
22+
description: "The description of the issue"
23+
type: string
24+
position: 2
25+
assignee_ids:
26+
description: "The comma-separated list of assignee IDs"
27+
type: string
28+
position: 3
29+
labels:
30+
description: "The comma-separated list of labels"
31+
type: string
32+
position: 4
33+
epic_id:
34+
description: "The ID of the epic to which the issue should be linked"
35+
type: integer
36+
position: 5
37+
due_date:
38+
description: "The fixed due date of the issue"
39+
type: string
40+
position: 6
41+
weight:
42+
description: "The weight of the issue"
43+
type: integer
44+
position: 7
45+
token:
46+
description: "Gitlab token"
47+
type: string

pack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: gitlab
33
description: GitLab Rest API
44
keywords:
55
- gitlab
6-
version: 1.1.1
6+
version: 1.1.2
77
author: Daniel Chamot
88
99
python_versions:

0 commit comments

Comments
 (0)