Skip to content
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

Add action to create an issue #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## v1.1.2

* New action `issue.create`

## v1.1.1

* Fix - Remove default group id

## v1.1.0

* Use of `python-gitlab` library
* New action `epic.create`

## v1.0.1

* Small bug fixes regarding Python 3 support
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ verify_ssl: False

## Actions

### Epics

* `epic.create` - Create new Epic

### Projects

* `project.info` - Returns project information

### Issues

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

### Pipelines

* `pipeline.list` - List all pipelines in a project
* `pipeline.trigger` - Create a new pipeline

32 changes: 32 additions & 0 deletions actions/epic_create.py
Original file line number Diff line number Diff line change
@@ -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)
39 changes: 39 additions & 0 deletions actions/epic_create.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---

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
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
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 actions/issue_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

from lib.gitlab import GitlabIssuesAPI
from lib.gitlabLib import GitlabIssuesAPI


class GitlabIssue(GitlabIssuesAPI):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion actions/pipeline_list.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

from lib.gitlab import GitlabPipelineAPI
from lib.gitlabLib import GitlabPipelineAPI


class GitlabPipeline(GitlabPipelineAPI):
Expand Down
2 changes: 1 addition & 1 deletion actions/pipeline_trigger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

from lib.gitlab import GitlabPipelineAPI
from lib.gitlabLib import GitlabPipelineAPI


class GitlabPipelineTrigger(GitlabPipelineAPI):
Expand Down
2 changes: 1 addition & 1 deletion actions/project_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

from lib.gitlab import GitlabProjectsAPI
from lib.gitlabLib import GitlabProjectsAPI


class GitlabProject(GitlabProjectsAPI):
Expand Down
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.0.1
version: 1.1.2
author: Daniel Chamot
email: daniel@nullkarma.com
python_versions:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
requests
python-gitlab
Loading