sys.path.insert(0, get_python_lib())
-import requests
-
-from common.gerrit import Gerrit, GerritError, get_gerrit_event
+from common.gerrit import Gerrit, get_gerrit_event
from common.git import clone_gitproject, fetch_change
from common.iris_rest_client import IrisRestClient
GERRIT_SILENT_MODE = int(os.getenv('GERRIT_SILENT_MODE'))
+def is_http_ok(status):
+ """
+ Returns True if HTTP status is OK
+ """
+ return status >= 200 and status < 300
+
+
def scm_check(client, gerrit, events, domains, gittrees):
"""
Print scm check information and return errors, check successfully
print result
print '########################################'
- if result['status'] == 200:
- try:
- gerrit.review(commit=events['patchset_revision'], verified=1)
- return 0
- except GerritError, err:
- print >> sys.stderr, 'Error posting review comment '\
- 'back to Gerrit: %s' % str(err)
- # return 1 if this exception is not caused by invalid commit
- if 'no such patch set' not in str(err):
- return 1
- elif result['status'] in [406, 500]:
- try:
- gerrit.review(commit=events['patchset_revision'],
- message=result['detail'], verified=-1)
- return 0
- except GerritError, err:
- print >> sys.stderr, 'Error posting review comment '\
- 'back to Gerrit: %s' % str(err)
- # return 1 if this exception is not caused by invalid commit
- if 'no such patch set' not in str(err):
- return 1
+ if is_http_ok(result['status']):
+ gerrit.review(commit=events['patchset_revision'],
+ message="SCM syntax & semantic check OK",
+ verified=1)
+ return 0
+
+ gerrit.review(commit=events['patchset_revision'],
+ message=result['detail'],
+ verified=-1)
return 1
result = client.scm_update(domains, gittrees)
print result
print '########################################'
-
- if result['status'] == 200:
- return 0
- return 1
+ return 0 if is_http_ok(result['status']) else 1
def main():
else:
return 1
+
if __name__ == '__main__':
sys.exit(main())