-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal_dev.py
More file actions
133 lines (118 loc) · 6.29 KB
/
Copy pathlocal_dev.py
File metadata and controls
133 lines (118 loc) · 6.29 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import get_ruleset_repo
import get_ruleset_org
import os
import json
import sys
# This Script will verify if the ruleset is present at the org or repo level
# These Global Variables are used for the workflow
TOKEN = os.environ.get("GITHUB_TOKEN") # Get the token from the environment
BASE_URL = "https://api.github.com"
# ORG = "liatrio-enterprise" # Name of the organization you want to read the ruleset from
# REPO = "all-rules-test" # Name of the repository you want to read the ruleset from
# RULESET_NAME = "Base Manifest" # CHANGE THIS to match the ruleset you created or want to read
# MANIFEST_FILE_NAME = "base.json" # CHANGE THIS to match the manifest file you created or want to read
HEADERS = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {TOKEN}",
"X-GitHub-Api-Version": "2022-11-28",
}
def main():
print("1.) Grab New Ruleset Manifest from Github Enterprise/Server and save file locally (ORG)")
print("2.) Grab New Ruleset Manifest from Github Enterprise/Server and save file locally (REPO)")
print("3.) Grab Latest Ruleset Manifest from Github Enterprise/Server and update file locally (ORG)")
print("4.) Grab Latest Ruleset Manifest from Github Enterprise/Server and update file locally (REPO)")
user_input = input("Please enter a selection: ")
if user_input == "1":
print("Grabbing New Ruleset Manifest from Github Enterprise/Server and saving file locally (ORG)")
print("What is the name of the org you want to grab the ruleset from?")
user_input = input("Please enter the org name: ")
org = user_input
print("What is the name of the ruleset you want to grab?")
user_input = input("Please enter the ruleset name: ")
ruleset_name = user_input
print("What is the name of the file you want to save the ruleset to?")
user_input = input("Please enter the manifest name: ")
manifest_file_name_save = user_input
responseORG = get_ruleset_org.main(BASE_URL, HEADERS, org, ruleset_name)
if responseORG is not None:
# Convert the response to JSON
responseORG_json = responseORG.text
json_data = json.loads(responseORG_json)
# Write the JSON data to a file
with open(f"./manifest/save/{manifest_file_name_save}.json", 'w') as json_file:
json.dump(json_data, json_file)
else:
print("No response found.")
elif user_input == "2":
print("Grabbing New Ruleset Manifest from Github Enterprise/Server and saving file locally (REPO)")
print("What is the name of the org you want to grab the ruleset from?")
user_input = input("Please enter the org name: ")
org = user_input
print("What is the name of the repo you want to grab the ruleset from?")
user_input = input("Please enter the repo name: ")
repo = user_input
print("What is the name of the ruleset you want to grab?")
user_input = input("Please enter the ruleset name: ")
ruleset_name = user_input
print("What is the name of the file you want to save the ruleset to?")
user_input = input("Please enter the manifest name: ")
manifest_file_name_save = user_input
responseREPO = get_ruleset_repo.main(BASE_URL, HEADERS, org, repo, ruleset_name)
if responseREPO is not None:
# Convert the response to JSON
responseREPO_json = responseREPO.text
json_data = json.loads(responseREPO_json)
# Write the JSON data to a file
with open(f"./manifest/save/{manifest_file_name_save}.json", 'w') as json_file:
json.dump(json_data, json_file)
else:
print("No response found.")
elif user_input == "3":
print("Grabbing Latest Ruleset Manifest from Github Enterprise/Server and updating file locally (ORG)")
print("What is the name of the org you want to grab the ruleset from?")
user_input = input("Please enter the org name: ")
org = user_input
print("What is the name of the ruleset you want to update?")
user_input = input("Please enter the ruleset name: ")
ruleset_name = user_input
print("What is the name of the file you want to update the ruleset to?")
user_input = input("Please enter the manifest name: ")
manifest_file_name = user_input
responseORG = get_ruleset_org.main(BASE_URL, HEADERS, org, ruleset_name)
if responseORG is not None:
# Convert the response to JSON
responseORG_json = responseORG.text
json_data = json.loads(responseORG_json)
# Write the JSON data to a file
with open(f"./manifest/org/{manifest_file_name}.json", 'w') as json_file:
json.dump(json_data, json_file)
else:
print("No response found.")
elif user_input == "4":
print("Grabbing Latest Ruleset Manifest from Github Enterprise/Server and updating file locally (REPO)")
print("What is the name of the org you want to grab the ruleset from?")
user_input = input("Please enter the org name: ")
org = user_input
print("What is the name of the repo you want to grab the ruleset from?")
user_input = input("Please enter the repo name: ")
repo = user_input
print("What is the name of the ruleset you want to update?")
user_input = input("Please enter the ruleset name: ")
ruleset_name = user_input
print("What is the name of the file you want to update the ruleset to?")
user_input = input("Please enter the manifest name: ")
manifest_file_name = user_input
responseREPO = get_ruleset_repo.main(BASE_URL, HEADERS, org, repo, ruleset_name)
if responseREPO is not None:
# Convert the response to JSON
responseREPO_json = responseREPO.text
json_data = json.loads(responseREPO_json)
# Write the JSON data to a file
with open(f"./manifest/repo/{manifest_file_name}.json", 'w') as json_file:
json.dump(json_data, json_file)
else:
print("No response found.")
else:
print("Invalid selection. Please select a number from the list.")
if __name__ == "__main__":
main()