Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ndebuhr committed Dec 9, 2020
1 parent bae7283 commit e51795f
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 69 deletions.
64 changes: 42 additions & 22 deletions src/main/resources/githubActions/CheckWorkflowRun.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,65 @@
"Authorization": "Token {}".format(server["accessToken"]),
}

request = HttpRequest(
{
"url": server["url"],
"authenticationMethod": "None",
"username": None,
"password": None,
"domain": None,
"proxyHost": server["proxyHost"],
"proxyPort": server["proxyPort"],
"proxyUsername": server["proxyUsername"],
"proxyPassword": server["proxyPassword"],
}
)

if runIdScript is None:
r = requests.get(
server["url"] + "/repos/{}/{}/actions/workflows/{}/runs?per_page=1".format(owner, repository, workflowId),
response = request.get(
"/repos/{}/{}/actions/workflows/{}/runs?per_page=1".format(
owner, repository, workflowId
),
headers=headers,
verify=False
)
if not r.ok:
raise Exception("GitHub Responded With HTTP Status Code {}".format(r.status_code))
if not response.isSuccessful():
raise Exception(response.status, response.headers, response.response)
else:
response = r.json()
runIdScript = response["workflow_runs"][0]["id"]
runIdScript = json.loads(response.response)["workflow_runs"][0]["id"]
task.schedule("githubActions/CheckWorkflowRun.py", 3)

else:
r = requests.get(
server["url"] + "/repos/{}/{}/actions/runs/{}?per_page=1".format(owner, repository, runIdScript),
response = request.get(
"/repos/{}/{}/actions/runs/{}?per_page=1".format(
owner, repository, runIdScript
),
headers=headers,
verify=False
)
if not r.ok:
raise Exception("GitHub Responded With HTTP Status Code {}".format(r.status_code))
if not response.isSuccessful():
raise Exception(response.status, response.headers, response.response)
else:
response = r.json()
status = response["status"]
data = json.loads(response.response)
status = data["status"]

if status == "completed":
runId = runIdScript
conclusion = response["conclusion"]
html_url = response["html_url"]
conclusion = data["conclusion"]
html_url = data["html_url"]
if conclusion == "success":
task.setStatusLine(status.title())
print("GitHub Actions [workflow run {}]({}) conclusion: {}".format(runIdScript, html_url, conclusion.title()))
print(
"GitHub Actions [workflow run {}]({}) conclusion: {}".format(
runIdScript, html_url, conclusion.title()
)
)
# No more LOC after this, so task will complete
else:
task.setStatusLine(status.title())
raise Exception("GitHub Actions [workflow run {}]({}) conclusion: {}".format(runIdScript, html_url, conclusion.title()))
raise Exception(
"GitHub Actions [workflow run {}]({}) conclusion: {}".format(
runIdScript, html_url, conclusion.title()
)
)
else:
task.setStatusLine(status.title().replace("_", " ") + "...")
task.schedule("githubActions/CheckWorkflowRun.py", 3)



25 changes: 16 additions & 9 deletions src/main/resources/githubActions/Server.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import requests
# get the configuration properties from the UI
params = {
"url": configuration.url,
"authenticationMethod": "None",
"username": None,
"password": None,
"domain": None,
"proxyHost": configuration.proxyHost,
"proxyPort": configuration.proxyPort,
"proxyUsername": configuration.proxyUsername,
"proxyPassword": configuration.proxyPassword,
}

headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Token {}".format(configuration.accessToken),
}

r = requests.get(
configuration.url,
json="",
headers=headers,
verify=False
)
request = HttpRequest(params)
response = request.get("/", headers=headers)

if not r.status_code == requests.codes.ok:
raise Exception("GitHub Responded With HTTP Status Code {}".format(r.status_code))
if not response.isSuccessful():
raise Exception(response.status, response.headers, response.response)
81 changes: 53 additions & 28 deletions src/main/resources/githubActions/TriggerWorkflowRun.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,88 @@
"Authorization": "Token {}".format(server["accessToken"]),
}

request = HttpRequest(
{
"url": server["url"],
"authenticationMethod": "None",
"username": None,
"password": None,
"domain": None,
"proxyHost": server["proxyHost"],
"proxyPort": server["proxyPort"],
"proxyUsername": server["proxyUsername"],
"proxyPassword": server["proxyPassword"],
}
)

if not triggered:
body = {
"ref": ref,
# "inputs": inputs
}
r = requests.post(
server["url"] + "/repos/{}/{}/actions/workflows/{}/dispatches".format(owner, repository, workflowId),
json=body,

response = request.post(
"/repos/{}/{}/actions/workflows/{}/dispatches".format(
owner, repository, workflowId
),
body=json.dumps(body),
headers=headers,
verify=False
)
if not r.ok:
raise Exception("GitHub Responded With HTTP Status Code {}".format(r.status_code))

if not response.isSuccessful():
raise Exception(response.status, response.headers, response.response)
else:
triggered = True
task.setStatusLine("Triggering...")
task.schedule("githubActions/TriggerWorkflowRun.py", 3)

elif runIdScript is None and triggered:
r = requests.get(
server["url"] + "/repos/{}/{}/actions/workflows/{}/runs?per_page=1".format(owner, repository, workflowId),
response = request.get(
"/repos/{}/{}/actions/workflows/{}/runs?per_page=1".format(
owner, repository, workflowId
),
headers=headers,
verify=False
)
if not r.ok:
raise Exception("GitHub Responded With HTTP Status Code {}".format(r.status_code))

if not response.isSuccessful():
raise Exception(response.status, response.headers, response.response)
else:
response = r.json()
runIdScript = response["workflow_runs"][0]["id"]
runIdScript = json.loads(response.response)["workflow_runs"][0]["id"]
task.schedule("githubActions/TriggerWorkflowRun.py", 3)

elif runIdScript is not None and triggered:
r = requests.get(
server["url"] + "/repos/{}/{}/actions/runs/{}?per_page=1".format(owner, repository, runIdScript),
response = request.get(
"/repos/{}/{}/actions/runs/{}?per_page=1".format(
owner, repository, runIdScript
),
headers=headers,
verify=False
)
if not r.ok:
raise Exception("GitHub Responded With HTTP Status Code {}".format(r.status_code))

if not response.isSuccessful():
raise Exception(response.status, response.headers, response.response)
else:
response = r.json()
status = response["status"]
data = json.loads(response.response)
status = data["status"]

if status == "completed":
runId = runIdScript
conclusion = response["conclusion"]
html_url = response["html_url"]
conclusion = data["conclusion"]
html_url = data["html_url"]
if conclusion == "success":
task.setStatusLine(status.title())
print("GitHub Actions [workflow run {}]({}) conclusion: {}".format(runIdScript, html_url, conclusion.title()))
print(
"GitHub Actions [workflow run {}]({}) conclusion: {}".format(
runIdScript, html_url, conclusion.title()
)
)
# No more LOC after this, so task will complete
else:
task.setStatusLine(status.title())
raise Exception("GitHub Actions [workflow run {}]({}) conclusion: {}".format(runIdScript, html_url, conclusion.title()))
raise Exception(
"GitHub Actions [workflow run {}]({}) conclusion: {}".format(
runIdScript, html_url, conclusion.title()
)
)
else:
task.setStatusLine(status.title().replace("_", " ") + "...")
task.schedule("githubActions/TriggerWorkflowRun.py", 3)



31 changes: 21 additions & 10 deletions src/main/resources/githubActions/WorkflowRunsTimelineTile.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
import json
import requests

headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Token {}".format(server["accessToken"]),
}

r = requests.get(
server["url"] + "/repos/{}/{}/actions/workflows/{}/runs?per_page={}".format(owner, repository, workflowId, count),
request = HttpRequest(
{
"url": server["url"],
"authenticationMethod": "None",
"username": None,
"password": None,
"domain": None,
"proxyHost": server["proxyHost"],
"proxyPort": server["proxyPort"],
"proxyUsername": server["proxyUsername"],
"proxyPassword": server["proxyPassword"],
}
)

response = request.get(
"/repos/{}/{}/actions/workflows/{}/runs?per_page={}".format(
owner, repository, workflowId, count
),
headers=headers,
verify=False
)

if not r.ok:
raise Exception("GitHub Responded With HTTP Status Code {}".format(r.status_code))
if not response.isSuccessful():
raise Exception(response.status, response.headers, response.response)

data = {
"raw": r.json(),
"runsNumberToShow": count
}
data = {"raw": json.loads(response.response), "runsNumberToShow": count}

0 comments on commit e51795f

Please sign in to comment.