123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- '''
- Script to determine if this commit has also
- been merged through the stage branch
- '''
- import sys
- import subprocess
- def run_cli_cmd(cmd, in_stdout=None, in_stderr=None):
- '''Run a command and return its output'''
- if not in_stderr:
- proc = subprocess.Popen(cmd, bufsize=-1, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=False)
- else:
- proc = subprocess.check_output(cmd, bufsize=-1, stdout=in_stdout, stderr=in_stderr, shell=False)
- stdout, stderr = proc.communicate()
- if proc.returncode != 0:
- return {"rc": proc.returncode, "error": stderr}
- else:
- return {"rc": proc.returncode, "result": stdout}
- def main():
- '''Check to ensure that the commit that is currently
- being submitted is also in the stage branch.
- if it is, succeed
- else, fail
- '''
- branch = 'prod'
- if sys.argv[1] != branch:
- sys.exit(0)
-
- results = run_cli_cmd(['/usr/bin/git', 'checkout', 'stg'])
-
- results = run_cli_cmd(['/usr/bin/git', 'pull'])
-
- results = run_cli_cmd(['/usr/bin/git', 'checkout', 'prod'])
- results = run_cli_cmd(['/usr/bin/git', 'pull'])
-
- commit_id = sys.argv[2]
- results = run_cli_cmd(['/usr/bin/git', 'merge', commit_id])
-
- results = run_cli_cmd(['/usr/bin/git', 'rev-list', '--left-right', 'stg...prod'])
-
- if results['rc'] != 0:
- print results['error']
- sys.exit(results['rc'])
- count = 0
-
-
- for commit in results['result'].split('\n'):
-
- if not commit or commit.startswith('<'):
- continue
-
- commit = commit[1:]
-
- results = run_cli_cmd(['/usr/bin/git', 'branch', '-q', '-r', '--contains', commit], in_stderr=None)
-
-
- if results['rc'] == 0 and len(results['result']) == 0:
- continue
-
-
-
-
-
- if 'origin/stg' not in results['result']:
- print "\nFAILED: (These commits are not in stage.)\n"
- print "\t%s" % commit
- count += 1
-
- sys.exit(count)
- if __name__ == '__main__':
- main()
|