Merge lp:~3v1n0/ubuntu-bots/github-support into lp:ubuntu-bots

Proposed by Marco Trevisan (Treviño)
Status: Needs review
Proposed branch: lp:~3v1n0/ubuntu-bots/github-support
Merge into: lp:ubuntu-bots
Diff against target: 168 lines (+90/-4)
3 files modified
Bugtracker/README.txt (+2/-0)
Bugtracker/plugin.py (+87/-4)
README.txt (+1/-0)
To merge this branch: bzr merge lp:~3v1n0/ubuntu-bots/github-support
Reviewer Review Type Date Requested Status
Ubuntu IRC Bots Pending
Review via email: mp+342155@code.launchpad.net

Commit message

Bugtracker: Add github support

To post a comment you must log in.
lp:~3v1n0/ubuntu-bots/github-support updated
322. By Marco Trevisan (Treviño)

Bugtracker: add support for trackers with multiple sub-trackers

Properly log pull requests in Github

323. By Marco Trevisan (Treviño)

Bugtracker: add ext info for Github

Unmerged revisions

323. By Marco Trevisan (Treviño)

Bugtracker: add ext info for Github

322. By Marco Trevisan (Treviño)

Bugtracker: add support for trackers with multiple sub-trackers

Properly log pull requests in Github

321. By Marco Trevisan (Treviño)

Bugtracker: Add github support

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Bugtracker/README.txt'
--- Bugtracker/README.txt 2011-05-28 06:33:21 +0000
+++ Bugtracker/README.txt 2018-03-26 23:08:26 +0000
@@ -7,6 +7,7 @@
7@bugtracker add openoffice issuezilla http://www.openoffice.org/issues OpenOffice7@bugtracker add openoffice issuezilla http://www.openoffice.org/issues OpenOffice
8@bugtracker add django trac http://code.djangoproject.com/ticket Django8@bugtracker add django trac http://code.djangoproject.com/ticket Django
9@bugtracker add gaim sourceforge http://sourceforge.net/tracker/?group_id=235&atid=100235 Gaim9@bugtracker add gaim sourceforge http://sourceforge.net/tracker/?group_id=235&atid=100235 Gaim
10@bugtracker add snapcore github https://github.com/snapcore Snapcraft
1011
11In general: @bugtracker add <name> <type> <baseurl> [description]12In general: @bugtracker add <name> <type> <baseurl> [description]
12Bugtracker dialects (types) this plugin understands:13Bugtracker dialects (types) this plugin understands:
@@ -18,6 +19,7 @@
18* WikiForms (see bugs.gnewsense.org for an example)19* WikiForms (see bugs.gnewsense.org for an example)
19* str.php from the CUPS project20* str.php from the CUPS project
20* Mantis (http://www.mantisbt.org)21* Mantis (http://www.mantisbt.org)
22* Github
2123
22A notable exception is Sourceforge. Unfortunatly, it has no API or data export24A notable exception is Sourceforge. Unfortunatly, it has no API or data export
23feature to output bug information in a well-formed way.25feature to output bug information in a well-formed way.
2426
=== modified file 'Bugtracker/plugin.py'
--- Bugtracker/plugin.py 2014-08-12 16:47:38 +0000
+++ Bugtracker/plugin.py 2018-03-26 23:08:26 +0000
@@ -419,7 +419,7 @@
419 irc.reply(makeClean(r), prefixNick=False)419 irc.reply(makeClean(r), prefixNick=False)
420420
421 def turlSnarfer(self, irc, msg, match):421 def turlSnarfer(self, irc, msg, match):
422 r"(?P<tracker>https?://\S*?)/(?:Bugs/0*|str.php\?L|show_bug.cgi\?id=|bugreport.cgi\?bug=|(?:bugs|\+bug)/|ticket/|tracker/|\S*aid=|bug=)?(?P<bug>\d+)(?P<sfurl>&group_id=\d+&at_id=\d+)?"422 r"(?P<tracker>https?://\S*?)/(?:Bugs/0*|str.php\?L|show_bug.cgi\?id=|bugreport.cgi\?bug=|(?:bugs|\+bug)/|ticket/|tracker/|\S*aid=|bug=|issues/|pull/)?(?P<bug>\d+)(?P<sfurl>&group_id=\d+&at_id=\d+)?"
423 channel = ircutils.isChannel(msg.args[0]) and msg.args[0] or None423 channel = ircutils.isChannel(msg.args[0]) and msg.args[0] or None
424 if not self.registryValue('bugSnarfer', channel):424 if not self.registryValue('bugSnarfer', channel):
425 return425 return
@@ -515,6 +515,8 @@
515 if '/' in url:515 if '/' in url:
516 url = url[:url.index('/')]516 url = url[:url.index('/')]
517 if url in snarfhost:517 if url in snarfhost:
518 if tracker.has_multiple_trackers():
519 return tracker.get_tracker(snarfurl)
518 return tracker520 return tracker
519521
520 if snarfhost == 'pad.lv': # Launchpad URL shortening522 if snarfhost == 'pad.lv': # Launchpad URL shortening
@@ -541,7 +543,7 @@
541 else:543 else:
542 (bid, product, title, severity, status, assignee, url) = r544 (bid, product, title, severity, status, assignee, url) = r
543545
544 severity = severity[0].upper() + severity[1:].lower()546 severity = severity[0].upper() + severity[1:].lower() if severity else ''
545 status = status[0].upper() + status[1:].lower()547 status = status[0].upper() + status[1:].lower()
546 tracker_name = tracker.description + ' '548 tracker_name = tracker.description + ' '
547 if not do_url:549 if not do_url:
@@ -575,8 +577,12 @@
575 def get_bug(self, id):577 def get_bug(self, id):
576 raise BugTrackerError("Bugtracker class does not implement get_bug")578 raise BugTrackerError("Bugtracker class does not implement get_bug")
577579
580 def has_multiple_trackers(self):
581 return False
582
578 def get_tracker(self, url):583 def get_tracker(self, url):
579 raise BugTrackerError("Bugtracker class does not implement get_tracker")584 if self.has_multiple_trackers():
585 raise BugTrackerError("Bugtracker class does not implement get_tracker")
580586
581 def __str__(self):587 def __str__(self):
582 return '%s(%s)' % (self.__class__.__name__, self.url)588 return '%s(%s)' % (self.__class__.__name__, self.url)
@@ -1057,6 +1063,82 @@
1057 except:1063 except:
1058 raise BugNotFoundError1064 raise BugNotFoundError
10591065
1066
1067class Github(IBugtracker):
1068 _gh = None
1069
1070 def __init__(self, *args, **kwargs):
1071 IBugtracker.__init__(self, *args, **kwargs)
1072
1073 if not Github._gh:
1074 try: # We need python-github
1075 from github import Github as GH
1076 Github._gh = GH(user_agent='PyGithub/ubuntu-bot')
1077 except ImportError:
1078 self.log.error("Please install python-github")
1079
1080 self.gh = Github._gh
1081 self.repo = None
1082
1083 def has_multiple_trackers(self):
1084 return True
1085
1086 def get_tracker(self, url):
1087 if not self.gh:
1088 return
1089 if not url:
1090 self.log.info("Impossible to get tracker for an empty url")
1091 return
1092
1093 try:
1094 url = url.replace('http://', 'https://', 1)
1095 if url.startswith(self.url):
1096 projectmatch = re.search("([^/]+/[^/]+)/(issues|pull)/\d+", url)
1097
1098 if projectmatch:
1099 repo_name = projectmatch.group(1)
1100 repo = self.gh.get_repo(repo_name)
1101 if not repo.has_issues:
1102 s = u'Repository {} has no issues'.format(repo_name)
1103 self.log.exception(s)
1104
1105 gh = Github(repo.full_name.replace('/', '-'), repo.html_url, repo.owner.login)
1106 gh.repo = repo
1107 return gh
1108
1109 except Exception as e:
1110 s = u'{}: Impossible to get tracker for {}: {}'.format(
1111 self.description, url, e)
1112 self.log.exception(s)
1113
1114 def get_bug(self, id):
1115 if not self.gh or not self.repo:
1116 self.log.info("Github or repository not initialized")
1117 return []
1118
1119 try:
1120 issue = self.repo.get_issue(id)
1121
1122 assignee = None
1123 labels = u', '.join([l.name for l in issue.labels])
1124 is_pull_request = issue.pull_request != None
1125
1126 if issue.assignee:
1127 assignee = u'{} ({})'.format(issue.assignee.login, issue.assignee.name)
1128 if is_pull_request:
1129 id = u'(Pull request) {}'.format(id)
1130
1131 # extinfo = "(comments: {}, reactions: {})" % (issue.comments, len(issue.get_reactions()))
1132 extinfo = "(comments: {})".format(issue.comments)
1133
1134 return [(id, self.repo.name, issue.title, labels, issue.state, assignee, issue.html_url, extinfo)]
1135 except Exception as e:
1136 s = u'{}: Impossible to get infos for {} issue {}: {}'.format(
1137 self.description, self.repo.full_name, id, e)
1138 self.log.exception(s)
1139 raise BugtrackerError, s
1140
1141
1060# Introspection is quite cool1142# Introspection is quite cool
1061defined_bugtrackers = {}1143defined_bugtrackers = {}
1062v = vars()1144v = vars()
@@ -1084,6 +1166,7 @@
1084registerBugtracker('supybot', 'http://sourceforge.net/tracker/?group_id=58965&atid=489447', 'Supybot', 'sourceforge')1166registerBugtracker('supybot', 'http://sourceforge.net/tracker/?group_id=58965&atid=489447', 'Supybot', 'sourceforge')
1085registerBugtracker('mantis', "http://www.mantisbt.org/bugs", "Mantis", 'mantis')1167registerBugtracker('mantis', "http://www.mantisbt.org/bugs", "Mantis", 'mantis')
1086registerBugtracker('ubottu', 'https://launchpad.net', 'Ubottu', 'launchpad')1168registerBugtracker('ubottu', 'https://launchpad.net', 'Ubottu', 'launchpad')
1169registerBugtracker('sourceforge', 'http://sourceforge.net/tracker/', 'Sourceforge', 'sourceforge')
1170registerBugtracker('github', 'https://github.com', 'Github', 'github')
1087# Don't delete this one1171# Don't delete this one
1088registerBugtracker('sourceforge', 'http://sourceforge.net/tracker/', 'Sourceforge', 'sourceforge')
1089Class = Bugtracker1172Class = Bugtracker
10901173
=== modified file 'README.txt'
--- README.txt 2011-05-28 06:33:21 +0000
+++ README.txt 2018-03-26 23:08:26 +0000
@@ -18,6 +18,7 @@
1818
19(Optional)19(Optional)
20Launchpadlib python-launchpadlib https://launchpad.net/launchpadlib20Launchpadlib python-launchpadlib https://launchpad.net/launchpadlib
21PyGithub python-github https://github.com/PyGithub/PyGithub
21apt-file apt-file N/A Debian (and derivatives) only22apt-file apt-file N/A Debian (and derivatives) only
2223
23Launchpadlib will become a required module for Bugtracker (and possibly others)24Launchpadlib will become a required module for Bugtracker (and possibly others)

Subscribers

People subscribed via source and target branches