-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the core login for the action
- Loading branch information
1 parent
e70adea
commit 318a824
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM python:3.7 | ||
|
||
RUN pip install --no-cache-dir requests | ||
|
||
COPY . . | ||
|
||
CMD [ "python", "/main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: "Validate Issues over Pull Requests" | ||
description: "Checks for a valid Issue number linked with the PR" | ||
author: "Harsh Mishra" | ||
|
||
inputs: | ||
prbody: | ||
description: "Body of the Pull Request to search for related issues" | ||
required: true | ||
|
||
prurl: | ||
description: "URL of the Pull Request" | ||
required: true | ||
|
||
outputs: | ||
valid: | ||
description: "code for a valid issue (0=Invalid, 1=Valid)" | ||
|
||
runs: | ||
using: "docker" | ||
image: "Dockerfile" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import os | ||
import re | ||
|
||
import requests | ||
|
||
|
||
def main(): | ||
""" | ||
Function to validate the Issue present over the Pull Request body. | ||
""" | ||
|
||
pattern = "#\d+" | ||
|
||
# Get the PR body and the PR URL | ||
body = os.getenv("INPUT_PRBODY") | ||
url = os.getenv("INPUT_PRURL") | ||
print(body) | ||
print(url) | ||
|
||
# Get the Issue number | ||
try: | ||
issue_num = re.search(pattern, body)[0].replace("#", "") | ||
print(issue_num) | ||
except: | ||
issue_num = "No issue number" | ||
|
||
# URL List will match: ['https:', '', 'api.github.com', 'repos', 'owner', 'repo-name'] | ||
url = url.split("/")[:-2] | ||
url[2] = url[2].replace("api.", "") | ||
|
||
# Get rid of the repos record | ||
url.pop(3) | ||
|
||
# Reattach the URL pieces | ||
url = "/".join(url) | ||
|
||
# Add the issue number to the URL | ||
url += "/issues/{}".format(issue_num) | ||
print(url) | ||
|
||
# Check if its valid code | ||
valid_code = 0 | ||
response = requests.get(url) | ||
if response.status_code == 200: | ||
if response.url == url: | ||
# Check if issue is open or closed | ||
text = response.text | ||
pattern_issue = "Status:\s(\w+)" | ||
if re.search(pattern_issue, text)[1] == "Open": | ||
valid_code = 1 | ||
else: | ||
print("Issue is closed") | ||
else: | ||
print( | ||
"Invalid Response Code obtained - error code: {}".format( | ||
response.status_code | ||
) | ||
) | ||
|
||
print("Valid flag is:", valid_code) | ||
print(f"::set-output name=valid::{valid_code}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |