-
Notifications
You must be signed in to change notification settings - Fork 888
67 lines (58 loc) · 3.04 KB
/
set-milestone-from-base-branch.yml
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
name: Set PR Milestone
on:
pull_request:
types: [closed]
branches: [master, 1.*]
concurrency: set-bb-issues-milestone
jobs:
set-pr-milestone:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest-2-cores
steps:
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_NAME: ${{ github.event.repository.full_name }}
PR_NUMBER: ${{ github.event.number }}
name: "Set milestone on PR based on base branch"
run: |
readarray -t milestones < <(gh api /repos/brave/brave-core/milestones -q ".[] | .title")
if [[ "$GITHUB_BASE_REF" = "master" ]]; then
milestone_selector="Nightly"
else
milestone_selector="$GITHUB_BASE_REF"
fi
milestone=$(printf "%s\n" "${milestones[@]}" | grep -F "$milestone_selector")
gh pr edit "$PR_NUMBER" -R "$REPO_NAME" -m "$milestone"
set-brave-browser-issues-milestone:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest-2-cores
needs: set-pr-milestone
steps:
- env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
REPO_NAME: ${{ github.event.repository.full_name }}
PR_NUMBER: ${{ github.event.number }}
name: "Set milestone on related issues in brave-browser"
run: |
BB_ISSUE_PREFIX="https://github.com/brave/brave-browser/issues/"
BB_ISSUE_URL_REGEX='(http(s)?:\/\/)?github.com/brave/brave-browser/issues/\d+'
UPLIFT_PR_REGEX='uplift\s+(?:of)?:?\s+\K(#\d+)'
RESOLVE_ISSUE_REGEX="(?:resolv|fix|clos)(?:e|es|ed)?:?\s+<?\K(${BB_ISSUE_URL_REGEX})"
verlte() { printf '%s\n%s' "$1" "$2" | sort -C -V; }
normalize_issue_links() { sed "s@\sbrave\/brave-browser\#\([0-9]\+\)@ ${BB_ISSUE_PREFIX}\1@g"; }
pr_body=$(gh pr view "${PR_NUMBER}" -R "${REPO_NAME}" --json body --jq .body | normalize_issue_links)
readarray -t issues_pr < <(echo "${pr_body}" | grep -ioP "${RESOLVE_ISSUE_REGEX}" || :)
echo "Looking for any uplifted PRs"
readarray -t prs < <(echo "${pr_body}" | grep -ioP "${UPLIFT_PR_REGEX}" || :)
readarray -t issues_uplift_pr < <(echo "${prs[@]}" | xargs -n 1 -I{} gh pr view {} -R brave/brave-core --json body --jq ".body" | normalize_issue_links | grep -ioP "${RESOLVE_ISSUE_REGEX}")
readarray -t issues < <(printf "%s\n" "${issues_pr[@]}" "${issues_uplift_pr[@]}"| sort -u | sed '/^\s*$/d')
echo "Relevant issues detected:"
printf "%s\n" "${issues[@]}"
pr_milestone=$(gh pr view "${PR_NUMBER}" -R "${REPO_NAME}" --json milestone --jq .milestone.title)
for issue in "${issues[@]}"; do
issue_milestone=$(gh issue view "${issue}" --json milestone --jq .milestone.title)
if [[ -z "${issue_milestone}" ]] || verlte "${pr_milestone}" "${issue_milestone}"; then
echo "Setting ${issue} milestone to ${pr_milestone}"
gh issue edit "${issue}" -m "${pr_milestone}"
fi
done