forked from apecloud/kubeblocks
-
Notifications
You must be signed in to change notification settings - Fork 3
87 lines (75 loc) · 2.76 KB
/
Copy pathpull-request-check.yml
File metadata and controls
87 lines (75 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: PULL-REQUEST-CHECK
on:
pull_request_target:
types: [ edited, opened ]
permissions:
issues: read
pull-requests: read
jobs:
pr-check:
name: PR Pre-Check
if: ${{ !(startsWith(github.head_ref, 'releasing-') && startsWith(github.base_ref, 'release-')) }}
runs-on: ubuntu-latest
steps:
- name: check branch name
if: github.event.pull_request.head.repo.full_name == github.repository
env:
HEAD_REF: ${{ github.head_ref }}
run: |
branch_pattern='^(feature/|bugfix/|release/|hotfix/|support/|releasing/|dependabot/)'
ignore_branch_pattern='^(main|master)$'
if [[ "$HEAD_REF" =~ $ignore_branch_pattern ]]; then
echo "This branch should be ignored"
exit 0
fi
if [[ "$HEAD_REF" =~ $branch_pattern ]]; then
echo "This branch has a valid name"
exit 0
fi
echo "::error::This branch name is not following the standards: feature/|bugfix/|release/|hotfix/|support/|releasing/|dependabot/"
exit 1
- name: check PR title
uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: check issue link
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
REPO_OWNER: ${{ github.repository_owner }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
if [[ "$PR_TITLE" == chore* || "$PR_TITLE" == docs* ]]; then
echo "PR skip the issue check"
exit 0
fi
repo_name="${REPO/${REPO_OWNER}\//}"
closing_issues_references="$(
gh api graphql \
-f owner="$REPO_OWNER" \
-f name="$repo_name" \
-F number="$PR_NUMBER" \
-f query='
query($owner: String!, $name: String!, $number: Int!) {
repository(owner: $owner, name: $name) {
pullRequest(number: $number) {
closingIssuesReferences(first: 10) {
edges {
node {
title
number
}
}
}
}
}
}' \
--jq '.data.repository.pullRequest.closingIssuesReferences.edges'
)"
echo "Closing Issues References: $closing_issues_references"
if [[ "$closing_issues_references" == "[]" ]]; then
echo "PR has no Issues References"
exit 1
fi
echo "PR has Issues References"