zk-merge-pr.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. #!/usr/bin/env python
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one or more
  4. # contributor license agreements. See the NOTICE file distributed with
  5. # this work for additional information regarding copyright ownership.
  6. # The ASF licenses this file to You under the Apache License, Version 2.0
  7. # (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. # Utility for creating well-formed pull request merges and pushing them to Apache. This script is a modified version
  19. # of the one created by the Spark project (https://github.com/apache/spark/blob/master/dev/merge_spark_pr.py).
  20. #
  21. # Usage: ./zk-merge-pr.py (see config env vars below)
  22. #
  23. # This utility assumes you already have a local ZooKeeper git folder and that you
  24. # have added remotes corresponding to both:
  25. # (i) the github apache ZooKeeper mirror and
  26. # (ii) the apache ZooKeeper git repo.
  27. import json
  28. import os
  29. import re
  30. import subprocess
  31. import sys
  32. import urllib2
  33. try:
  34. import jira.client
  35. JIRA_IMPORTED = True
  36. except ImportError:
  37. JIRA_IMPORTED = False
  38. PROJECT_NAME = "zookeeper"
  39. CAPITALIZED_PROJECT_NAME = PROJECT_NAME.upper()
  40. # Remote name which points to the GitHub site
  41. PR_REMOTE_NAME = os.environ.get("PR_REMOTE_NAME", "apache-github")
  42. # Remote name which points to Apache git
  43. PUSH_REMOTE_NAME = os.environ.get("PUSH_REMOTE_NAME", "apache")
  44. # ASF JIRA username
  45. JIRA_USERNAME = os.environ.get("JIRA_USERNAME", "")
  46. # ASF JIRA password
  47. JIRA_PASSWORD = os.environ.get("JIRA_PASSWORD", "")
  48. # OAuth key used for issuing requests against the GitHub API. If this is not defined, then requests
  49. # will be unauthenticated. You should only need to configure this if you find yourself regularly
  50. # exceeding your IP's unauthenticated request rate limit. You can create an OAuth key at
  51. # https://github.com/settings/tokens. This script only requires the "public_repo" scope.
  52. GITHUB_OAUTH_KEY = os.environ.get("GITHUB_OAUTH_KEY")
  53. GITHUB_USER = os.environ.get("GITHUB_USER", "apache")
  54. GITHUB_BASE = "https://github.com/%s/%s/pull" % (GITHUB_USER, PROJECT_NAME)
  55. GITHUB_API_BASE = "https://api.github.com/repos/%s/%s" % (GITHUB_USER, PROJECT_NAME)
  56. JIRA_BASE = "https://issues.apache.org/jira/browse"
  57. JIRA_API_BASE = "https://issues.apache.org/jira"
  58. # Prefix added to temporary branches
  59. TEMP_BRANCH_PREFIX = "PR_TOOL"
  60. # TODO Introduce a convention as this is too brittle
  61. RELEASE_BRANCH_PREFIX = "branch-"
  62. DEV_BRANCH_NAME = "master"
  63. DEFAULT_FIX_VERSION = os.environ.get("DEFAULT_FIX_VERSION", "branch-3.5")
  64. def get_json(url):
  65. try:
  66. request = urllib2.Request(url)
  67. if GITHUB_OAUTH_KEY:
  68. request.add_header('Authorization', 'token %s' % GITHUB_OAUTH_KEY)
  69. return json.load(urllib2.urlopen(request))
  70. except urllib2.HTTPError as e:
  71. if "X-RateLimit-Remaining" in e.headers and e.headers["X-RateLimit-Remaining"] == '0':
  72. print "Exceeded the GitHub API rate limit; see the instructions in " + \
  73. "zk-merge-pr.py to configure an OAuth token for making authenticated " + \
  74. "GitHub requests."
  75. else:
  76. print "Unable to fetch URL, exiting: %s" % url
  77. sys.exit(-1)
  78. def fail(msg):
  79. print msg
  80. clean_up()
  81. sys.exit(-1)
  82. def run_cmd(cmd):
  83. print cmd
  84. if isinstance(cmd, list):
  85. return subprocess.check_output(cmd)
  86. else:
  87. return subprocess.check_output(cmd.split(" "))
  88. def continue_maybe(prompt):
  89. result = raw_input("\n%s (y/n): " % prompt)
  90. if result.lower().strip() != "y":
  91. fail("Okay, exiting")
  92. def clean_up():
  93. if original_head != get_current_branch():
  94. print "Restoring head pointer to %s" % original_head
  95. run_cmd("git checkout %s" % original_head)
  96. branches = run_cmd("git branch").replace(" ", "").split("\n")
  97. for branch in filter(lambda x: x.startswith(TEMP_BRANCH_PREFIX), branches):
  98. print "Deleting local branch %s" % branch
  99. run_cmd("git branch -D %s" % branch)
  100. def get_current_branch():
  101. return run_cmd("git rev-parse --abbrev-ref HEAD").replace("\n", "")
  102. # merge the requested PR and return the merge hash
  103. def merge_pr(pr_num, target_ref, title, body, pr_repo_desc):
  104. pr_branch_name = "%s_MERGE_PR_%s" % (TEMP_BRANCH_PREFIX, pr_num)
  105. target_branch_name = "%s_MERGE_PR_%s_%s" % (TEMP_BRANCH_PREFIX, pr_num, target_ref.upper())
  106. run_cmd("git fetch %s pull/%s/head:%s" % (PR_REMOTE_NAME, pr_num, pr_branch_name))
  107. run_cmd("git fetch %s %s:%s" % (PUSH_REMOTE_NAME, target_ref, target_branch_name))
  108. run_cmd("git checkout %s" % target_branch_name)
  109. had_conflicts = False
  110. try:
  111. run_cmd(['git', 'merge', pr_branch_name, '--squash'])
  112. except Exception as e:
  113. msg = "Error merging: %s\nWould you like to manually fix-up this merge?" % e
  114. continue_maybe(msg)
  115. msg = "Okay, please fix any conflicts and 'git add' conflicting files... Finished?"
  116. continue_maybe(msg)
  117. had_conflicts = True
  118. commit_authors = run_cmd(['git', 'log', 'HEAD..%s' % pr_branch_name,
  119. '--pretty=format:%an <%ae>']).split("\n")
  120. distinct_authors = sorted(set(commit_authors),
  121. key=lambda x: commit_authors.count(x), reverse=True)
  122. primary_author = raw_input(
  123. "Enter primary author in the format of \"name <email>\" [%s]: " %
  124. distinct_authors[0])
  125. if primary_author == "":
  126. primary_author = distinct_authors[0]
  127. reviewers = raw_input(
  128. "Enter reviewers in the format of \"name1 <email1>, name2 <email2>\": ").strip()
  129. commits = run_cmd(['git', 'log', 'HEAD..%s' % pr_branch_name,
  130. '--pretty=format:%h [%an] %s']).split("\n")
  131. if len(commits) > 1:
  132. result = raw_input("List pull request commits in squashed commit message? (y/n): ")
  133. if result.lower().strip() == "y":
  134. should_list_commits = True
  135. else:
  136. should_list_commits = False
  137. else:
  138. should_list_commits = False
  139. merge_message_flags = []
  140. merge_message_flags += ["-m", title]
  141. if body is not None:
  142. # We remove @ symbols from the body to avoid triggering e-mails
  143. # to people every time someone creates a public fork of the project.
  144. merge_message_flags += ["-m", body.replace("@", "")]
  145. authors = "\n".join(["Author: %s" % a for a in distinct_authors])
  146. merge_message_flags += ["-m", authors]
  147. if (reviewers != ""):
  148. merge_message_flags += ["-m", "Reviewers: %s" % reviewers]
  149. if had_conflicts:
  150. committer_name = run_cmd("git config --get user.name").strip()
  151. committer_email = run_cmd("git config --get user.email").strip()
  152. message = "This patch had conflicts when merged, resolved by\nCommitter: %s <%s>" % (
  153. committer_name, committer_email)
  154. merge_message_flags += ["-m", message]
  155. # The string "Closes #%s" string is required for GitHub to correctly close the PR
  156. close_line = "Closes #%s from %s" % (pr_num, pr_repo_desc)
  157. if should_list_commits:
  158. close_line += " and squashes the following commits:"
  159. merge_message_flags += ["-m", close_line]
  160. if should_list_commits:
  161. merge_message_flags += ["-m", "\n".join(commits)]
  162. run_cmd(['git', 'commit', '--author="%s"' % primary_author] + merge_message_flags)
  163. continue_maybe("Merge complete (local ref %s). Push to %s?" % (
  164. target_branch_name, PUSH_REMOTE_NAME))
  165. try:
  166. run_cmd('git push %s %s:%s' % (PUSH_REMOTE_NAME, target_branch_name, target_ref))
  167. except Exception as e:
  168. clean_up()
  169. fail("Exception while pushing: %s" % e)
  170. merge_hash = run_cmd("git rev-parse %s" % target_branch_name)[:8]
  171. clean_up()
  172. print("Pull request #%s merged!" % pr_num)
  173. print("Merge hash: %s" % merge_hash)
  174. return merge_hash
  175. def cherry_pick(pr_num, merge_hash, default_branch):
  176. pick_ref = raw_input("Enter a branch name [%s]: " % default_branch)
  177. if pick_ref == "":
  178. pick_ref = default_branch
  179. pick_branch_name = "%s_PICK_PR_%s_%s" % (TEMP_BRANCH_PREFIX, pr_num, pick_ref.upper())
  180. run_cmd("git fetch %s %s:%s" % (PUSH_REMOTE_NAME, pick_ref, pick_branch_name))
  181. run_cmd("git checkout %s" % pick_branch_name)
  182. try:
  183. run_cmd("git cherry-pick -sx %s" % merge_hash)
  184. except Exception as e:
  185. msg = "Error cherry-picking: %s\nWould you like to manually fix-up this merge?" % e
  186. continue_maybe(msg)
  187. msg = "Okay, please fix any conflicts and finish the cherry-pick. Finished?"
  188. continue_maybe(msg)
  189. continue_maybe("Pick complete (local ref %s). Push to %s?" % (
  190. pick_branch_name, PUSH_REMOTE_NAME))
  191. try:
  192. run_cmd('git push %s %s:%s' % (PUSH_REMOTE_NAME, pick_branch_name, pick_ref))
  193. except Exception as e:
  194. clean_up()
  195. fail("Exception while pushing: %s" % e)
  196. pick_hash = run_cmd("git rev-parse %s" % pick_branch_name)[:8]
  197. clean_up()
  198. print("Pull request #%s picked into %s!" % (pr_num, pick_ref))
  199. print("Pick hash: %s" % pick_hash)
  200. return pick_ref
  201. def fix_version_from_branch(branch, versions):
  202. # Note: Assumes this is a sorted (newest->oldest) list of un-released versions
  203. if branch == DEV_BRANCH_NAME:
  204. versions = filter(lambda x: x == DEFAULT_FIX_VERSION, versions)
  205. if len(versions) > 0:
  206. return versions[0]
  207. else:
  208. return None
  209. else:
  210. versions = filter(lambda x: x.startswith(branch), versions)
  211. if len(versions) > 0:
  212. return versions[-1]
  213. else:
  214. return None
  215. def resolve_jira_issue(merge_branches, comment, default_jira_id=""):
  216. asf_jira = jira.client.JIRA({'server': JIRA_API_BASE},
  217. basic_auth=(JIRA_USERNAME, JIRA_PASSWORD))
  218. jira_id = raw_input("Enter a JIRA id [%s]: " % default_jira_id)
  219. if jira_id == "":
  220. jira_id = default_jira_id
  221. try:
  222. issue = asf_jira.issue(jira_id)
  223. except Exception as e:
  224. fail("ASF JIRA could not find %s\n%s" % (jira_id, e))
  225. cur_status = issue.fields.status.name
  226. cur_summary = issue.fields.summary
  227. cur_assignee = issue.fields.assignee
  228. if cur_assignee is None:
  229. cur_assignee = "NOT ASSIGNED!!!"
  230. else:
  231. cur_assignee = cur_assignee.displayName
  232. if cur_status == "Resolved" or cur_status == "Closed":
  233. fail("JIRA issue %s already has status '%s'" % (jira_id, cur_status))
  234. print ("=== JIRA %s ===" % jira_id)
  235. print ("summary\t\t%s\nassignee\t%s\nstatus\t\t%s\nurl\t\t%s/%s\n" % (
  236. cur_summary, cur_assignee, cur_status, JIRA_BASE, jira_id))
  237. versions = asf_jira.project_versions(CAPITALIZED_PROJECT_NAME)
  238. versions = sorted(versions, key=lambda x: x.name, reverse=True)
  239. versions = filter(lambda x: x.raw['released'] is False, versions)
  240. version_names = map(lambda x: x.name, versions)
  241. default_fix_versions = map(lambda x: fix_version_from_branch(x, version_names), merge_branches)
  242. default_fix_versions = filter(lambda x: x != None, default_fix_versions)
  243. default_fix_versions = ",".join(default_fix_versions)
  244. fix_versions = raw_input("Enter comma-separated fix version(s) [%s]: " % default_fix_versions)
  245. if fix_versions == "":
  246. fix_versions = default_fix_versions
  247. fix_versions = fix_versions.replace(" ", "").split(",")
  248. def get_version_json(version_str):
  249. return filter(lambda v: v.name == version_str, versions)[0].raw
  250. jira_fix_versions = map(lambda v: get_version_json(v), fix_versions)
  251. resolve = filter(lambda a: a['name'] == "Resolve Issue", asf_jira.transitions(jira_id))[0]
  252. resolution = filter(lambda r: r.raw['name'] == "Fixed", asf_jira.resolutions())[0]
  253. asf_jira.transition_issue(
  254. jira_id, resolve["id"], fixVersions = jira_fix_versions,
  255. comment = comment, resolution = {'id': resolution.raw['id']})
  256. print "Successfully resolved %s with fixVersions=%s!" % (jira_id, fix_versions)
  257. def resolve_jira_issues(title, merge_branches, comment):
  258. jira_ids = re.findall("%s-[0-9]{4,5}" % CAPITALIZED_PROJECT_NAME, title)
  259. if len(jira_ids) == 0:
  260. resolve_jira_issue(merge_branches, comment)
  261. for jira_id in jira_ids:
  262. resolve_jira_issue(merge_branches, comment, jira_id)
  263. def standardize_jira_ref(text):
  264. """
  265. Standardize the jira reference commit message prefix to "PROJECT_NAME-XXX: Issue"
  266. >>> standardize_jira_ref("%s-5954: Top by key" % CAPITALIZED_PROJECT_NAME)
  267. 'ZOOKEEPER-5954: Top by key'
  268. >>> standardize_jira_ref("%s-5821: ParquetRelation2 CTAS should check if delete is successful" % PROJECT_NAME)
  269. 'ZOOKEEPER-5821: ParquetRelation2 CTAS should check if delete is successful'
  270. >>> standardize_jira_ref("%s-4123: [WIP] Show new dependencies added in pull requests" % PROJECT_NAME)
  271. 'ZOOKEEPER-4123: [WIP] Show new dependencies added in pull requests'
  272. >>> standardize_jira_ref("%s 5954: Top by key" % PROJECT_NAME)
  273. 'ZOOKEEPER-5954: Top by key'
  274. >>> standardize_jira_ref("%s-979: a LRU scheduler for load balancing in TaskSchedulerImpl" % PROJECT_NAME)
  275. 'ZOOKEEPER-979: a LRU scheduler for load balancing in TaskSchedulerImpl'
  276. >>> standardize_jira_ref("%s-1094: Support MiMa for reporting binary compatibility across versions." % CAPITALIZED_PROJECT_NAME)
  277. 'ZOOKEEPER-1094: Support MiMa for reporting binary compatibility across versions.'
  278. >>> standardize_jira_ref("%s-1146: [WIP] Vagrant support" % CAPITALIZED_PROJECT_NAME)
  279. 'ZOOKEEPER-1146: [WIP] Vagrant support'
  280. >>> standardize_jira_ref("%s-1032: If Yarn app fails before registering, app master stays aroun..." % PROJECT_NAME)
  281. 'ZOOKEEPER-1032: If Yarn app fails before registering, app master stays aroun...'
  282. >>> standardize_jira_ref("%s-6250 %s-6146 %s-5911: Types are now reserved words in DDL parser." % (PROJECT_NAME, PROJECT_NAME, CAPITALIZED_PROJECT_NAME))
  283. 'ZOOKEEPER-6250 ZOOKEEPER-6146 ZOOKEEPER-5911: Types are now reserved words in DDL parser.'
  284. >>> standardize_jira_ref("Additional information for users building from source code")
  285. 'Additional information for users building from source code'
  286. """
  287. jira_refs = []
  288. components = []
  289. # Extract JIRA ref(s):
  290. pattern = re.compile(r'(%s[-\s]*[0-9]{3,6})+' % CAPITALIZED_PROJECT_NAME, re.IGNORECASE)
  291. for ref in pattern.findall(text):
  292. # Add brackets, replace spaces with a dash, & convert to uppercase
  293. jira_refs.append(re.sub(r'\s+', '-', ref.upper()))
  294. text = text.replace(ref, '')
  295. # Extract project name component(s):
  296. # Look for alphanumeric chars, spaces, dashes, periods, and/or commas
  297. pattern = re.compile(r'(\[[\w\s,-\.]+\])', re.IGNORECASE)
  298. for component in pattern.findall(text):
  299. components.append(component.upper())
  300. text = text.replace(component, '')
  301. # Cleanup any remaining symbols:
  302. pattern = re.compile(r'^\W+(.*)', re.IGNORECASE)
  303. if (pattern.search(text) is not None):
  304. text = pattern.search(text).groups()[0]
  305. # Assemble full text (JIRA ref(s), module(s), remaining text)
  306. jira_prefix = ' '.join(jira_refs).strip()
  307. if jira_prefix:
  308. jira_prefix = jira_prefix + ": "
  309. clean_text = jira_prefix + ' '.join(components).strip() + " " + text.strip()
  310. # Replace multiple spaces with a single space, e.g. if no jira refs and/or components were included
  311. clean_text = re.sub(r'\s+', ' ', clean_text.strip())
  312. return clean_text
  313. def get_remote_repos():
  314. repos = run_cmd("git remote -v").split()
  315. dict = {}
  316. for i in range(0, len(repos), 3):
  317. dict[repos[i]] = repos[i+1]
  318. return dict
  319. def check_git_remote():
  320. repos = get_remote_repos()
  321. # check if all remote endpoints' URLs point to project git repo
  322. name = PROJECT_NAME + ".git"
  323. for url in repos.values():
  324. if not url.endswith(name):
  325. fail("Error: not a %s git repo or at least one remote is invalid" % PROJECT_NAME)
  326. if not PR_REMOTE_NAME in repos:
  327. fail("Error: PR_REMOTE_NAME (%s) environment variable has not been set!" % PR_REMOTE_NAME)
  328. if not PUSH_REMOTE_NAME in repos:
  329. fail("Error: PUSH_REMOTE_NAME (%s) environment variable has not been set!" % PUSH_REMOTE_NAME)
  330. def check_jira_env():
  331. if JIRA_IMPORTED:
  332. if JIRA_USERNAME.strip() == "" or JIRA_PASSWORD.strip() == "":
  333. msg ="JIRA credentials are not set. Want to continue?"
  334. continue_maybe(msg)
  335. def main():
  336. global original_head
  337. original_head = get_current_branch()
  338. check_jira_env()
  339. check_git_remote()
  340. branches = get_json("%s/branches" % GITHUB_API_BASE)
  341. branch_names = filter(lambda x: x.startswith(RELEASE_BRANCH_PREFIX), [x['name'] for x in branches])
  342. # Assumes branch names can be sorted lexicographically
  343. latest_branch = sorted(branch_names, reverse=True)[0]
  344. pr_num = raw_input("Which pull request would you like to merge? (e.g. 34): ")
  345. pr = get_json("%s/pulls/%s" % (GITHUB_API_BASE, pr_num))
  346. pr_events = get_json("%s/issues/%s/events" % (GITHUB_API_BASE, pr_num))
  347. url = pr["url"]
  348. pr_title = pr["title"]
  349. commit_title = raw_input("Commit title [%s]: " % pr_title.encode("utf-8")).decode("utf-8")
  350. if commit_title == "":
  351. commit_title = pr_title
  352. # Decide whether to use the modified title or not
  353. modified_title = standardize_jira_ref(commit_title)
  354. if modified_title != commit_title:
  355. print "I've re-written the title as follows to match the standard format:"
  356. print "Original: %s" % commit_title
  357. print "Modified: %s" % modified_title
  358. result = raw_input("Would you like to use the modified title? (y/n): ")
  359. if result.lower().strip() == "y":
  360. commit_title = modified_title
  361. print "Using modified title:"
  362. else:
  363. print "Using original title:"
  364. print commit_title
  365. body = pr["body"]
  366. target_ref = pr["base"]["ref"]
  367. user_login = pr["user"]["login"]
  368. base_ref = pr["head"]["ref"]
  369. pr_repo_desc = "%s/%s" % (user_login, base_ref)
  370. # Merged pull requests don't appear as merged in the GitHub API;
  371. # Instead, they're closed by asfgit.
  372. merge_commits = \
  373. [e for e in pr_events if e["actor"]["login"] == "asfgit" and e["event"] == "closed"]
  374. if merge_commits:
  375. merge_hash = merge_commits[0]["commit_id"]
  376. message = get_json("%s/commits/%s" % (GITHUB_API_BASE, merge_hash))["commit"]["message"]
  377. print "Pull request %s has already been merged, assuming you want to backport" % pr_num
  378. commit_is_downloaded = run_cmd(['git', 'rev-parse', '--quiet', '--verify',
  379. "%s^{commit}" % merge_hash]).strip() != ""
  380. if not commit_is_downloaded:
  381. fail("Couldn't find any merge commit for #%s, you may need to update HEAD." % pr_num)
  382. print "Found commit %s:\n%s" % (merge_hash, message)
  383. cherry_pick(pr_num, merge_hash, latest_branch)
  384. sys.exit(0)
  385. if not bool(pr["mergeable"]):
  386. msg = "Pull request %s is not mergeable in its current form.\n" % pr_num + \
  387. "Continue? (experts only!)"
  388. continue_maybe(msg)
  389. print ("\n=== Pull Request #%s ===" % pr_num)
  390. print ("PR title\t%s\nCommit title\t%s\nSource\t\t%s\nTarget\t\t%s\nURL\t\t%s" % (
  391. pr_title, commit_title, pr_repo_desc, target_ref, url))
  392. continue_maybe("Proceed with merging pull request #%s?" % pr_num)
  393. merged_refs = [target_ref]
  394. merge_hash = merge_pr(pr_num, target_ref, commit_title, body, pr_repo_desc)
  395. pick_prompt = "Would you like to pick %s into another branch?" % merge_hash
  396. while raw_input("\n%s (y/n): " % pick_prompt).lower().strip() == "y":
  397. merged_refs = merged_refs + [cherry_pick(pr_num, merge_hash, latest_branch)]
  398. if JIRA_IMPORTED:
  399. if JIRA_USERNAME and JIRA_PASSWORD:
  400. continue_maybe("Would you like to update an associated JIRA?")
  401. jira_comment = "Issue resolved by pull request %s\n[%s/%s]" % (pr_num, GITHUB_BASE, pr_num)
  402. resolve_jira_issues(commit_title, merged_refs, jira_comment)
  403. else:
  404. print "JIRA_USERNAME and JIRA_PASSWORD not set"
  405. print "Exiting without trying to close the associated JIRA."
  406. else:
  407. print "Could not find jira-python library. Run 'sudo pip install jira' to install."
  408. print "Exiting without trying to close the associated JIRA."
  409. if __name__ == "__main__":
  410. import doctest
  411. (failure_count, test_count) = doctest.testmod()
  412. if (failure_count):
  413. exit(-1)
  414. main()