SABER
update_webhook_branchname.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 # (C) Copyright 2019 UCAR
4 #
5 # This software is licensed under the terms of the Apache Licence Version 2.0
6 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
7 
8 """
9 Codebuild Runs this script to check for branches with
10 same names accross dependent repos. Then creates a
11 webhook on PR page to notify users if such a branch exists.
12 
13 Call as:
14 update_webhook_branchname.py branchName commitId
15 """
16 
17 import os
18 import boto3
19 from github import Github
20 import sys
21 
22 branchName = sys.argv[1]
23 commitId = sys.argv[2]
24 
25 
26 # check other repos
27 repoList = ["atlas", "oops", "ioda", "ufo", "soca", "fv3-jedi", "mpas-jedi"]
28 
29 token = os.getenv('GIT_PASS', '...')
30 g = Github(token)
31 ownerList = ["JCSDA", "jcsda-internal"]
32 
33 saberRepo = g.get_repo("jcsda/saber")
34 
35 for owner in ownerList:
36  for repoName in repoList:
37  branchExists = True
38  repo = g.get_repo(f"{owner}/{repoName}")
39  branchList = list(repo.get_branches())
40  try:
41  repo.get_branch(branchName)
42  except Exception:
43  pass
44  branchExists = False
45 
46  if (branchExists):
47  print(branchName + ' exists in '+owner+'/'+repoName)
48  stageDescription= branchName+" exists in "+owner+'/'+ repoName
49  commitStatus = saberRepo.get_commit(sha=commitId).create_status(
50  state="pending",
51  description=stageDescription,
52  context="Branch Check-"+owner+'/'+repoName)
53  else:
54  print(branchName + ' does not exist in '+owner+'/'+repoName)