Skip to content

Commit

Permalink
Add action issue.create using gitlab-python library
Browse files Browse the repository at this point in the history
  • Loading branch information
Manon Delahaye committed Feb 6, 2024
1 parent 9f79b30 commit 0fec6d2
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.1.2

* New action `issue.create`

## v1.1.1

* Fix - Remove default group id
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ verify_ssl: False
### Issues

* `issue.info` - Returns issue information
* `issue.create` - Create new Issue

### Pipelines

Expand Down
30 changes: 30 additions & 0 deletions actions/issue_create.py
Original file line number Diff line number Diff line change
@@ -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)
47 changes: 47 additions & 0 deletions actions/issue_create.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0fec6d2

Please sign in to comment.