diff --git a/src/main/resources/githubActions/CheckWorkflowRun.py b/src/main/resources/githubActions/CheckWorkflowRun.py index 9282588..146a194 100644 --- a/src/main/resources/githubActions/CheckWorkflowRun.py +++ b/src/main/resources/githubActions/CheckWorkflowRun.py @@ -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) - - - \ No newline at end of file diff --git a/src/main/resources/githubActions/Server.py b/src/main/resources/githubActions/Server.py index cf7b9eb..39bf355 100644 --- a/src/main/resources/githubActions/Server.py +++ b/src/main/resources/githubActions/Server.py @@ -1,4 +1,15 @@ -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", @@ -6,12 +17,8 @@ "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)) \ No newline at end of file +if not response.isSuccessful(): + raise Exception(response.status, response.headers, response.response) diff --git a/src/main/resources/githubActions/TriggerWorkflowRun.py b/src/main/resources/githubActions/TriggerWorkflowRun.py index 3d3c1ec..44fe970 100644 --- a/src/main/resources/githubActions/TriggerWorkflowRun.py +++ b/src/main/resources/githubActions/TriggerWorkflowRun.py @@ -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) - - - \ No newline at end of file diff --git a/src/main/resources/githubActions/WorkflowRunsTimelineTile.py b/src/main/resources/githubActions/WorkflowRunsTimelineTile.py index 5bd832f..91a4f4a 100644 --- a/src/main/resources/githubActions/WorkflowRunsTimelineTile.py +++ b/src/main/resources/githubActions/WorkflowRunsTimelineTile.py @@ -1,5 +1,4 @@ import json -import requests headers = { "Accept": "application/json", @@ -7,16 +6,28 @@ "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}