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/04 01:50:25 UTC

[incubator-linkis-website] branch dev updated: reduce github action redundant code (#398)

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 0e9edceb5 reduce github action redundant code (#398)
0e9edceb5 is described below

commit 0e9edceb51be5b2b02acac0a6fb433a96e2150aa
Author: Beacontownfc <89...@users.noreply.github.com>
AuthorDate: Mon Jul 4 09:50:20 2022 +0800

    reduce github action redundant code (#398)
---
 .../actions/Auto_close_associate_issue/Dockerfile  |  5 +++
 .../actions/Auto_close_associate_issue/action.yml  | 16 ++++++++
 .github/actions/Auto_close_associate_issue/main.js |  7 ++++
 .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             | 11 +++--
 7 files changed, 33 insertions(+), 80 deletions(-)

diff --git a/.github/actions/Auto_close_associate_issue/Dockerfile b/.github/actions/Auto_close_associate_issue/Dockerfile
new file mode 100644
index 000000000..8827d3e59
--- /dev/null
+++ b/.github/actions/Auto_close_associate_issue/Dockerfile
@@ -0,0 +1,5 @@
+FROM node:10.15
+
+COPY . .
+
+CMD [ "node", "/main.js"]
\ No newline at end of file
diff --git a/.github/actions/Auto_close_associate_issue/action.yml b/.github/actions/Auto_close_associate_issue/action.yml
new file mode 100644
index 000000000..729630a2b
--- /dev/null
+++ b/.github/actions/Auto_close_associate_issue/action.yml
@@ -0,0 +1,16 @@
+name: "Auto_close_associate_issue"
+
+description: "Auto close an issue which associate with a PR."
+
+inputs:
+  prbody:
+    description: "The body of the PR to search for related issues"
+    required: true
+
+outputs:
+  issurNumber:
+    description: "The issue number"
+
+runs:
+  using: "docker"
+  image: "Dockerfile"
\ No newline at end of file
diff --git a/.github/actions/Auto_close_associate_issue/main.js b/.github/actions/Auto_close_associate_issue/main.js
new file mode 100644
index 000000000..78f9fdd7a
--- /dev/null
+++ b/.github/actions/Auto_close_associate_issue/main.js
@@ -0,0 +1,7 @@
+let body = process.env['INPUT_PRBODY'];
+
+let pattern = /#\d+/;
+
+let issueNumber = body.match(pattern)[0].replace('#', '');
+
+console.log(`::set-output name=issueNumber::${issueNumber}`);
diff --git a/.github/actions/PR_has_a_valid_issue/Dockerfile b/.github/actions/PR_has_a_valid_issue/Dockerfile
deleted file mode 100644
index f793839b6..000000000
--- a/.github/actions/PR_has_a_valid_issue/Dockerfile
+++ /dev/null
@@ -1,7 +0,0 @@
-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
deleted file mode 100644
index 468ebc99a..000000000
--- a/.github/actions/PR_has_a_valid_issue/action.yml
+++ /dev/null
@@ -1,20 +0,0 @@
-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
deleted file mode 100644
index 8eb2e1d48..000000000
--- a/.github/actions/PR_has_a_valid_issue/main.py
+++ /dev/null
@@ -1,47 +0,0 @@
-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
index 0fb524a86..b8049b838 100644
--- a/.github/workflows/auto-close-issue.yml
+++ b/.github/workflows/auto-close-issue.yml
@@ -10,19 +10,18 @@ jobs:
     steps:
       - uses: actions/checkout@v2
 
-      - name: "Issue number validator"
-        uses: ./.github/actions/PR_has_a_valid_issue/
-        id: validator
+      - name: "Auto issue closer"
+        uses: ./.github/actions/Auto_close_associate_issue/
+        id: Closer
         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
+          issue-number: ${{ steps.Closer.outputs.issueNumber }}
+          comment: The associated PR has been merged, this issue is automatically closed, you can reopend if necessary.
         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