Move issue check logic to GitHub script (#7486)
* Fixed new line strip regex * Move issue check logic to GitHub script * Fixed variable name issueBody
This commit is contained in:
parent
6b3b65be35
commit
c2dd232564
2 changed files with 24 additions and 85 deletions
41
.github/workflows/issue-check-support.yml
vendored
41
.github/workflows/issue-check-support.yml
vendored
|
|
@ -19,21 +19,10 @@ jobs:
|
|||
ISSUE_NUMBER: ${{ github.event.issue.number || github.event.inputs.issue_number }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Python venv
|
||||
uses: ./.github/actions/init-python
|
||||
with:
|
||||
cache-key: "issue-check-support"
|
||||
|
||||
- name: Check issue
|
||||
id: issue-check
|
||||
run: ./scripts/github.py --issue-check-tech-support
|
||||
|
||||
- name: Add comment for customer
|
||||
if: steps.issue-check.outputs.may-need-tech-support == 'true'
|
||||
env:
|
||||
CUSTOMER_PATTERN: What type of Synergy user are you\?\s*Customer
|
||||
NO_TICKET_PATTERN: Support ticket number \(for customers\)\s*_No response_
|
||||
COMMENT_BODY: |
|
||||
Hello! :wave: As a customer, you're entitled to tech support which is included in your
|
||||
license at no extra cost.
|
||||
|
|
@ -44,15 +33,31 @@ jobs:
|
|||
uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
issue_number = process.env.ISSUE_NUMBER
|
||||
body = process.env.COMMENT_BODY
|
||||
const issueNumber = process.env.ISSUE_NUMBER;
|
||||
const issueBody = process.env.ISSUE_BODY;
|
||||
const customerPattern = new RegExp(process.env.CUSTOMER_PATTERN);
|
||||
const noTicketPattern = new RegExp(process.env.NO_TICKET_PATTERN);
|
||||
|
||||
const isCustomer = customerPattern.test(issueBody);
|
||||
const noTicket = noTicketPattern.test(issueBody);
|
||||
|
||||
if (!isCustomer) {
|
||||
console.log('Not a customer');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!noTicket) {
|
||||
console.log('Already has a ticket');
|
||||
return;
|
||||
}
|
||||
|
||||
// Strip newlines, since GitHub comments are not markdown.
|
||||
body = body.replace(/\\n/g, ' ')
|
||||
const commentBody = process.env.COMMENT_BODY.replace(/\n/g, ' ');
|
||||
|
||||
console.log('Adding comment to issue:', issueNumber);
|
||||
github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number,
|
||||
body
|
||||
issue_number: issueNumber,
|
||||
body: commentBody
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,66 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Synergy -- mouse and keyboard sharing utility
|
||||
# Copyright (C) 2024 Symless Ltd.
|
||||
#
|
||||
# This package is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# found in the file LICENSE that should have accompanied this file.
|
||||
#
|
||||
# This package is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import lib.env as env
|
||||
|
||||
env.ensure_in_venv(__file__)
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
import re
|
||||
import lib.github as github
|
||||
|
||||
ISSUE_BODY_ENV = "ISSUE_BODY"
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--issue-check-tech-support",
|
||||
action="store_true",
|
||||
help="Check if an issue may need tech support",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.issue_check_tech_support:
|
||||
issue_check_tech_support()
|
||||
else:
|
||||
print("No command specified", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def issue_check_tech_support():
|
||||
print("Checking if issue may need tech support")
|
||||
|
||||
issue_body = env.get_env(ISSUE_BODY_ENV)
|
||||
print(f'Issue body...\n"{issue_body}"\n')
|
||||
|
||||
customer_pattern = r"What type of Synergy user are you\?\s*Customer"
|
||||
missing_ticket_pattern = r"Support ticket number \(for customers\)\s*_No response_"
|
||||
|
||||
is_customer = re.search(customer_pattern, issue_body, re.DOTALL)
|
||||
no_ticket = re.search(missing_ticket_pattern, issue_body, re.DOTALL)
|
||||
|
||||
print(f"Is customer: {is_customer}")
|
||||
print(f"No ticket: {no_ticket}")
|
||||
|
||||
may_need_tech_support = bool(is_customer and no_ticket)
|
||||
github.set_output("may-need-tech-support", str(may_need_tech_support).lower())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in a new issue