OOPS
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 downstream 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 = ["ufo", "saber", "ioda", "soca", "fv3-jedi", "mpas-jedi", "shallow-water"]
28 
29 token = os.getenv('GIT_PASS', '...')
30 g = Github(token)
31 owner = "JCSDA"
32 
33 oopsRepo = g.get_repo("jcsda/oops")
34 
35 for repoName in repoList:
36  branchExists = True
37  repo = g.get_repo(f"{owner}/{repoName}")
38  branchList = list(repo.get_branches())
39  try:
40  repo.get_branch(branchName)
41  except Exception:
42  pass
43  branchExists = False
44 
45  if (branchExists):
46  print(branchName + ' exists in '+repoName)
47  stageDescription= branchName+" exists in "+ repoName
48  commitStatus = oopsRepo.get_commit(sha=commitId).create_status(
49  state="pending",
50  description=stageDescription,
51  context="Branch Check-"+repoName)
52  else:
53  print(branchName + ' does not exist in '+repoName)