This repository has been archived by the owner on Jan 31, 2024. It is now read-only.
forked from heitortsergent/python-trigger-sample
-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_runscope_triggers.py
56 lines (41 loc) · 1.73 KB
/
get_runscope_triggers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import json
import requests
import sys
import os
BRANCH_INFIX = "BRANCH"
def extract_relevant_tests_from_bucket(bucketInfo, brunchName, authorization):
url = bucketInfo["tests_url"]
headers = {"Content-Type": "application/json", "Authorization": "Bearer " + authorization}
params = {"count": 100}
response = requests.get(url = url, headers = headers, params = params)
accumulate = []
for testInfo in response.json()['data']:
branchInfixAndName = BRANCH_INFIX + " " + brunchName
descriptionContainsBranchName = (testInfo['description'] is not None) and (branchInfixAndName in testInfo['description'])
descriptionNotContainsAnyBranch = (testInfo['description'] is None) or ((testInfo['description'] is not None) and (BRANCH_INFIX not in testInfo['description']))
if descriptionContainsBranchName or descriptionNotContainsAnyBranch:
data = {}
data["name"] = testInfo["name"]
data["trigger_url"] = testInfo["trigger_url"]
accumulate.append(data)
return accumulate
def get_relevant_tests_triggers(readFile, branchName, authorization):
testTriggers = []
with open(readFile, 'r') as file:
bucketsInfo = json.load(file)
for bucketInfo in bucketsInfo:
bucketTestTriggers = extract_relevant_tests_from_bucket(bucketInfo, branchName, authorization)
testTriggers.extend(bucketTestTriggers)
return testTriggers
def write_to_file(input, outputeFile):
outFile = open(outputeFile, "w")
outFile.write(json.dumps(input))
outFile.write(os.linesep)
outFile.close()
if __name__ == '__main__':
readFile = sys.argv[1]
writeFile = sys.argv[2]
branchName = sys.argv[3]
authorization = sys.argv[4]
relevantTestsTriggers = get_relevant_tests_triggers(readFile, branchName, authorization)
write_to_file(relevantTestsTriggers, writeFile)