You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by ca...@apache.org on 2022/07/01 14:51:43 UTC
[incubator-linkis-website] branch dev updated: add an auto close issue bot
This is an automated email from the ASF dual-hosted git repository.
casion pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-linkis-website.git
The following commit(s) were added to refs/heads/dev by this push:
new 3e51410d0 add an auto close issue bot
new 240b29ab9 Merge pull request #392 from Beacontownfc/auto-close-issue
3e51410d0 is described below
commit 3e51410d06c72672e78ef6fbac207382cb3ff06e
Author: Beacontownfc <19...@qq.com>
AuthorDate: Fri Jul 1 08:08:30 2022 +0800
add an auto close issue bot
---
.github/actions/PR_has_a_valid_issue/Dockerfile | 7 ++++
.github/actions/PR_has_a_valid_issue/action.yml | 20 +++++++++++
.github/actions/PR_has_a_valid_issue/main.py | 47 +++++++++++++++++++++++++
.github/workflows/auto-close-issue.yml | 28 +++++++++++++++
4 files changed, 102 insertions(+)
diff --git a/.github/actions/PR_has_a_valid_issue/Dockerfile b/.github/actions/PR_has_a_valid_issue/Dockerfile
new file mode 100644
index 000000000..f793839b6
--- /dev/null
+++ b/.github/actions/PR_has_a_valid_issue/Dockerfile
@@ -0,0 +1,7 @@
+FROM python:3
+
+RUN pip install --no-cache-dir requests
+
+COPY . .
+
+CMD [ "python", "/main.py"]
\ No newline at end of file
diff --git a/.github/actions/PR_has_a_valid_issue/action.yml b/.github/actions/PR_has_a_valid_issue/action.yml
new file mode 100644
index 000000000..468ebc99a
--- /dev/null
+++ b/.github/actions/PR_has_a_valid_issue/action.yml
@@ -0,0 +1,20 @@
+name: "PR_has_a_valid_issue"
+
+description: "Checks for a valid Issue number linked with the PR"
+
+inputs:
+ prbody:
+ description: "The body of the PR 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"
\ No newline at end of file
diff --git a/.github/actions/PR_has_a_valid_issue/main.py b/.github/actions/PR_has_a_valid_issue/main.py
new file mode 100644
index 000000000..8eb2e1d48
--- /dev/null
+++ b/.github/actions/PR_has_a_valid_issue/main.py
@@ -0,0 +1,47 @@
+import os, re, requests
+
+# Used pattern to search for Issues.
+pattern = "#\d+"
+
+# PR body
+body = os.getenv("INPUT_PRBODY")
+# PR URL
+url = os.getenv("INPUT_PRURL")
+
+issue_num = re.search(pattern, body)[0].replace("#", "")
+
+# url list will be something like this
+# ['https:', '', 'api.github.com', 'repos', 'owner', 'repo-name']
+# Split URL using slashes
+url = url.split("/")[:-2]
+# Replace API URL with HTML URL
+url[2] = url[2].replace("api.", "")
+# Get rid of "repos" record
+url.pop(3)
+# Reattach URL pieces
+url = "/".join(url)
+# Add issue number
+url += "/issues/{}".format(issue_num)
+
+# Is valid code
+valid_code = 0
+response = requests.get(url)
+# Check if not a 404 page
+if response.status_code == 200:
+ print("status code is 200")
+ # Check if not redirected to a pull request page
+ if response.url == url:
+ print("URLS are matched")
+ # Check if Issue is Open not Closed
+ text = response.text
+ pattern_issue = "Status:\s(\w+)"
+ if re.search(pattern_issue, text)[1] == "Open":
+ valid_code = 1
+ else:
+ print("Couldn't find Open flag")
+else:
+ print("Invalid Response Code obtained - error code: {}".format(response.status_code))
+
+print("Valid flag is:", valid_code)
+
+print(f"::set-output name=issueNumber::{issue_num}")
diff --git a/.github/workflows/auto-close-issue.yml b/.github/workflows/auto-close-issue.yml
new file mode 100644
index 000000000..0fb524a86
--- /dev/null
+++ b/.github/workflows/auto-close-issue.yml
@@ -0,0 +1,28 @@
+name: Auto close issue when PR is merged
+
+on:
+ pull_request_target:
+ types: [ closed ]
+
+jobs:
+ close-issue:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: "Issue number validator"
+ uses: ./.github/actions/PR_has_a_valid_issue/
+ id: validator
+ with:
+ prbody: ${{ github.event.pull_request.body }}
+ prurl: ${{ github.event.pull_request.url }}
+
+ - name: Close Issue
+ uses: peter-evans/close-issue@v2
+ if: ${{ github.event.pull_request.merged }}
+ with:
+ issue-number: ${{ steps.validator.outputs.issueNumber }}
+ comment: Auto-closing issue
+ env:
+ Github_Token: ${{ secrets.GITHUB_TOKEN }}
+ PRNUM: ${{ github.event.pull_request.number }}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org