Created
January 13, 2015 14:49
-
-
Save hirokazumiyaji/40c9dffcb9f511295156 to your computer and use it in GitHub Desktop.
hubot stash api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description: | |
# Atlassian Stash API | |
# | |
# Dependencies: | |
# None | |
# | |
# Configurations: | |
# None | |
# Commands: | |
# None | |
# Notes: | |
# None | |
# | |
# Author: | |
# Hirokazu Miyaji | |
module.exports = (robot) -> | |
robot.respond /pull request ([-_a-zA-Z0-9\/]+:[-_a-zA-Z0-9\/]+) ([-_a-zA-Z0-9\/]+:[-_a-zA-Z0-9\/]+)/i, (msg) -> | |
[from_project_and_repository, from_branch] = msg.match[1].split(":") | |
[to_project_and_repository, to_branch] = msg.match[2].split(":") | |
if from_project_and_repository != to_project_and_repository | |
msg.send "Invalid Error Project And Repository. From:#{from_project_and_repository} To:#{to_project_and_repository}" | |
else | |
[project, repository] = from_project_and_repository.split("/") | |
data = JSON.stringify({ | |
state: "OPEN", | |
open: true, | |
closed: false, | |
fromRef: { | |
id: "refs/heads/#{from_branch}", | |
repository: { | |
slug: "#{repository}", | |
name: null, | |
project: { | |
key: "#{project}" | |
} | |
} | |
} | |
}, | |
toRef: { | |
id: "refs/heads/#{to_branch}", | |
repository: { | |
slug: "#{repository}", | |
name: null, | |
project: { | |
key: "#{project}" | |
} | |
} | |
} | |
locked: false, | |
reviewers: [ | |
{ | |
user: { | |
name: "example" | |
} | |
} | |
] | |
}) | |
msg.http("/rest/api/1.0/projects/#{project}/repos/#{repository}/pull-requests").post(data) (err, res, body) -> | |
res = JSON.parse(body) | |
id = res["id"] | |
url = "https://stash.atlassian.com/#{project}/repos/#{repository}/pullrequests/##{id}" | |
msg.send "Created #{url}" | |
#robot.respond /merge (https?|ftp)(:\/\/[-_.!~*¥'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/, (msg) -> | |
# url = msg.replace("/merge /", "") | |
# msg.send "Merged #{url}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment