Skip to content

Commit

Permalink
[qa] Fix python lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ppabcd committed Nov 21, 2018
1 parent 187d6cd commit 700a575
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions commitCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
repo = sys.argv[1]
commit = sys.argv[2]


# Function converter from php to python
def mb_substr(s, start, length=None) :
return (s[start :(start + length)])
def mb_substr(s, start, length=None):
return (s[start:(start + length)])


# Get Github token
Expand All @@ -34,36 +35,38 @@ def mb_substr(s, start, length=None) :
errors = []

# Check dot in end of the first line
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.")
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.")

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

if not prefix :
errors.append("Add prefix in beginning of the commit. Example: [module/file/feature]")
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() :
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 :
else:
body = "You have errors with commit message: \n"
for e in errors :
for e in errors:
body += "- " + e + "\n"

search = requests.get(api +
search = requests.get(
api +
'/search/issues?q=typetype:pr%20sha:'
+ mb_substr(commit, 0, 7) +
'%20is_unmerged%20author:'
Expand All @@ -75,12 +78,18 @@ def mb_substr(s, start, length=None) :

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 700a575

Please sign in to comment.