Skip to content

Commit

Permalink
[qa] Fix code linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ppabcd committed Nov 21, 2018
1 parent 71e7ed5 commit 0da2230
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions commitCheck.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import sys
import os
import requests
import json
import re
from urllib.parse import urlencode

# Get Repo and Commit Sha
repo = sys.argv[1]
Expand All @@ -13,14 +11,15 @@
def mb_substr(s,start,length=None) :
return (s[start:(start+length)])


# Get Github token
github_token = os.environ["GH_TOKEN"]

# Api URL and commit url
api = "https://api.github.com"
api_main_url = "/repos/"+repo+"/commits/"+commit
api_main_url = "/repos/" + repo + "/commits/" + commit

res = requests.get(api+api_main_url)
res = requests.get(api + api_main_url)
api_body = res.json()

# Get commit username
Expand All @@ -38,46 +37,52 @@ def mb_substr(s,start,length=None) :
if api_message_explode[0][
len(
api_message_explode[0].strip()
)-1].strip() == '.':
errors.append("Do not add a final dot at the end of the first line.")
)-1].strip() == '.' :
errors.append("Do not add a final dot at the end of the first line.")

# Check prefix
prefix = re.match('\[(.*?)\]', api_message_explode[0])

if not prefix:
if not prefix :
errors.append("Add prefix in beginning of the commit. Example: [module/file/feature]")

# Check capital after prefix
commitMessagefirst = api_message_explode[0].replace(prefix.group(),'').strip()
if not commitMessagefirst[0].isupper():
commitMessagefirst = api_message_explode[0].replace(prefix.group(), '').strip()
if not commitMessagefirst[0].isupper() :
errors.append("No capital letter after prefix")

# Check blank page before first line and second line
if api_message_explode_count > 1:
print(api_message_explode[1])
if api_message_explode[1] != '':
if api_message_explode[1] != '' :
errors.append("No blank line before first line and second line")

# Check is error
if len(errors) == 0:
if len(errors) == 0 :
body = "All check done, no errors."
else :
body = "You have errors with commit message: \n"
for e in errors:
body += "- "+e+"\n"

search = requests.get(api+'/search/issues?q=typetype:pr%20sha:'+mb_substr(commit,0 ,7)+'%20is_unmerged%20author:'+api_username+'&&sort=updated')
for e in errors :
body += "- " + e + "\n"

search = requests.get(api +
'/search/issues?q=typetype:pr%20sha:'
+ mb_substr(commit, 0, 7) +
'%20is_unmerged%20author:'
+ api_username +
'&&sort=updated'
)
search_body = search.json()


if len(search_body['items'])>0:
if len(search_body['items']) > 0 :
search_data = search_body['items'][0]['number']
response_url = "/repos/"+str(repo)+"/issues/"+str(search_data)+"/comments"
response_url = "/repos/" + str(repo) + "/issues/" + str(search_data) + "/comments"

headers = {
'Authorization': 'token %s' % github_token
}
post_fields = {
'body': body
}
review = requests.post(api+response_url,json=post_fields, headers=headers)
review = requests.post(api + response_url,json=post_fields, headers=headers)

0 comments on commit 0da2230

Please sign in to comment.