-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepos-branches-csv.py
57 lines (43 loc) · 1.82 KB
/
repos-branches-csv.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
from pymongo import MongoClient
import csv
import os
# Requires the PyMongo package.
# https://api.mongodb.com/python/current
# export SNOOTY_CONN_STRING='thing'
client = MongoClient(os.environ.get('SNOOTY_CONN_STRING'))
results = client['pool']['repos_branches'].find()
newData = []
for result in results:
repoName = result['repoName']
if repoName == "devhub-content":
continue
branches = result['branches']
print(repoName)
if len(branches) == 1:
newData.append({"repoName": repoName, "branchName": branches[0]['gitBranchName'], "url-version-component": ""})
for branch in branches:
if branch['active'] == False:
continue
branchName = branch.get('gitBranchName', '')
publishOriginalBranchName = branch.get('publishOriginalBranchName', '')
active = branch['active']
snooty = branch.get('buildsWithSnooty', '')
urlSlug = branch.get('urlSlug', branchName)
if snooty == False:
continue
urlAliases = branch.get('urlAliases', '')
stable = branch.get('isStableBranch', False)
if urlAliases:
for alias in urlAliases:
newData.append({"repoName": repoName, "branchName": branchName, "url-version-component": alias, "slug": urlSlug, "isStableBranch": stable})
if publishOriginalBranchName == True:
newData.append({"repoName": repoName, "branchName": branchName, "url-version-component": branchName, "slug": urlSlug, "isStableBranch": stable})
csv_columns = ["repoName", "branchName", "url-version-component", "slug", "isStableBranch"]
try:
with open('list.csv', 'w') as f:
writer = csv.DictWriter(f, fieldnames=csv_columns)
writer.writeheader()
for data in newData:
writer.writerow(data)
except IOError:
print("NOOOPE")