Skip to content

Commit 2405fd7

Browse files
committed
Add action for creating a pull request
1 parent 2cb107b commit 2405fd7

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

actions/create_pull_request.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from lib.action import BitBucketAction
2+
3+
4+
class CreatePullRequestAction(BitBucketAction):
5+
def run(self, project, repository, title, description, source, target, reviewers=None):
6+
client = self._get_stashy_client()
7+
return list(
8+
client.projects[project].repos[repository].pull_requests.create(
9+
title,
10+
description,
11+
source,
12+
target,
13+
reviewers))

actions/create_pull_request.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: create_pull_request
2+
description: Create a pull request
3+
enabled: true
4+
runner_type: python-script
5+
entry_point: create_pull_request.py
6+
parameters:
7+
project:
8+
type: string
9+
description: Bitbucket project the repo is under
10+
required: true
11+
repository:
12+
type: string
13+
description: Name of the repository
14+
required: true
15+
title:
16+
type: string
17+
description: Pull request title/short description
18+
required: true
19+
description:
20+
type: string
21+
description: Pull request description
22+
required: true
23+
source:
24+
type: string
25+
description: The branch name, tag, or commit hash to merge from
26+
required: true
27+
target:
28+
type: string
29+
description: The branch name, tag, or commit hash to merge into
30+
required: true
31+
reviewers:
32+
type: array
33+
description: List of usernames to add as reviewers
34+
required: false
35+
items:
36+
type: string

actions/lib/action.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ def _get_client(self, repo=None):
1515
bb = Bitbucket(username=self.config['email'],
1616
password=self.config['password'])
1717
return bb
18+
19+
def _get_stashy_client(self):
20+
# Late import to avoid clutter
21+
import stashy
22+
return stashy.connect(self.config['sensor']['bitbucket_server_url'],
23+
self.config['username'],
24+
self.config['password'])

0 commit comments

Comments
 (0)