def generateReport(self, rev, showDate=False): repo, author, comment, modified_paths, added_paths, removed_paths, date, rev = self.revision_info(rev) if showDate == True: msg = generate_report(repo, author, comment, modified_paths, added_paths, removed_paths, rev, date) else: msg = generate_report(repo, author, comment, modified_paths, added_paths, removed_paths, rev, "") return msg
def do_POST(self): length = int(self.headers['Content-Length']) indata = self.rfile.read(length) #print("indata: "+str(indata)) #print("headers: "+str(self.headers)) post_data = urllib.parse.parse_qs(indata.decode('utf-8')) if len(post_data) == 0: post_data = indata.decode('utf-8') #try: # payload = query_parsed['payload'][0] #except KeyError: #self.phenny.say("Something went wrong with getting the data. WHAT.") #self.send_response(403) #return #self.phenny.say(post_data['payload'][0]) if "payload" in post_data: data = json.loads(post_data['payload'][0]) else: #print(post_data) data = json.loads(post_data) #print(data) msgs = [] if "commits" in data: for commit in data['commits']: try: if "committer" in commit: ## For github msgs.append(generate_report('phenny', data['pusher']['name'], commit['message'], commit['modified'], commit['added'], commit['removed'], commit['id'][:7])) elif "pusher" in data: # for google code for commit in data['revisions']: msgs.append(generate_report(data['project_name'], commit['author'], commit['message'], commit['modified'], commit['added'], commit['removed'], commit['revision'])) elif "author" in commit: ## For bitbucket #msgs.append("unsupported data: "+str(commit)) files = self.getBBFiles(commit['files']) msgs.append(generate_report('turkiccorpora', commit['author'], commit['message'], files['modified'], files['added'], files['removed'], commit['node'])) else: msgs.append("unsupported data: "+str(commit)) except Exception: #msgs.append("unsupported data: "+str(commit)) print("unsupported data: "+str(commit)) if len(msgs)==0: msgs = ["Something went wrong: "+str(data)] for msg in msgs: for chan in self.phInput.chans: self.phenny.bot.msg(chan, msg) self.send_response(200)
def return_data(self, site, data, commit): #hrm, if I'm storing fields in a list in python, but I have something that has complex fields (e.g., data['foo']['bar']), is there some way to write a function that'll #fields['github'] = ['phenny', data['pusher']['name'], commit['message'], commit['modified'], commit['added'], commit['removed'], commit['id'][:7])) if site=="github": name = "phenny" author = data['pusher']['name'] message = commit['message'] modified = commit['modified'] added = commit['added'] removed = commit['removed'] rev = commit['id'][:7] elif site=="googlecode": name = data['project_name'] author = commit['author'] message = commit['message'] modified = commit['modified'] added = commit['added'] removed = commit['removed'] rev = commit['revision'] elif site=="bitbucket": files = self.getBBFiles(commit['files']) name = 'turkiccorpora' author = commit['author'] message = commit['message'] modified = files['modified'] added = files['added'] removed = files['removed'] rev = commit['node'] return generate_report(name, author, message, modified, added, removed, rev)
def get_recent_commit(phenny, input): for repo in phenny.config.git_repositories: html = web.get(phenny.config.git_repositories[repo] + '/commits') data = json.loads(html) author, comment, modified_paths, added_paths, removed_paths, rev, date = get_commit_info(phenny, repo, data[0]['sha']) msg = generate_report(repo, author, comment, modified_paths, added_paths, removed_paths, rev, date) phenny.say(msg)
def retrieve_commit(phenny, input): '''Retreive commit information for a given repository and revision. This command is called as 'begiak: info <repo> <rev>'.''' # get repo and rev with regex data = input.group(1).split(' ') if len(data) != 2: phenny.reply("Invalid number of parameters.") return repo = data[0] rev = data[1] if repo in phenny.config.svn_repositories: # we don't handle SVN; see modules/svnpoller.py for that return if repo not in phenny.config.git_repositories: phenny.reply("That repository is not monitored by me!") return try: info, url = get_commit_info(phenny, repo, rev) except: phenny.reply("Invalid revision value!") return # the * is for unpacking msg = generate_report(repo, *info) # the URL is truncated so that it has at least 6 sha characters url = url[:url.rfind('/') + 7] phenny.say(truncate(msg, '{} ' + url))
def get_recent_commit(phenny, input): '''Get recent commit information for each repository Begiak monitors. This command is called as 'begiak: recent'.''' for repo in phenny.config.git_repositories: html = web.get(phenny.config.git_repositories[repo] + '/commits') data = json.loads(html) # the * is for unpacking msg = generate_report(repo, *get_commit_info()) phenny.say(msg)
def get_recent_commit(phenny, input): '''Get recent commit information for each repository Begiak monitors. This command is called as 'begiak: recent'.''' for repo in phenny.config.git_repositories: html = web.get(phenny.config.git_repositories[repo] + '/commits') data = json.loads(html) # the * is for unpacking info, url = get_commit_info(phenny, repo, data[0]['sha']) msg = generate_report(repo, *info) # the URL is truncated so that it has at least 6 sha characters url = url[:url.rfind('/') + 7] phenny.say(truncate(msg, '{} ' + url))
def return_data(self, site, data, commit): '''Generates a report for the specified site and commit.''' # fields = project name, author, commit message, modified files, added # files, removed files, revision fields = [] if site == "github": fields = [ data['repository']['name'], data['pusher']['name'], commit['message'], commit['modified'], commit['added'], commit['removed'], commit['id'][:7], ] elif site == "googlecode": fields = [ data['project_name'], commit['author'], commit['message'], commit['modified'], commit['added'], commit['removed'], commit['revision'], ] elif site == "bitbucket": files = self.getBBFiles(commit['files']) fields = [ 'turkiccorpora', commit['author'], commit['message'], files['modified'], files['added'], files['removed'], commit['node'], ] # the * is for unpacking return generate_report(*fields)
def retrieve_commit(phenny, input): data = input.group(1).split(' ') if len(data) != 2: phenny.reply("Invalid number of parameters.") return repo = data[0] rev = data[1] if repo in phenny.config.svn_repositories: return if repo not in phenny.config.git_repositories: phenny.reply("That repository is not monitored by me!") return try: author, comment, modified_paths, added_paths, removed_paths, rev, date = get_commit_info(phenny, repo, rev) except: phenny.reply("Invalid revision value!") return msg = generate_report(repo, author, comment, modified_paths, added_paths, removed_paths, rev, date) phenny.say(msg)
def generateReport(self, rev, showDate=False): repo, author, comment, modified, added, removed, date, rev = self.revision_info(rev) if not showDate: date = "" return generate_report(repo, author, comment, modified, added, removed, rev, date)