Skip to content

Commit ff4b713

Browse files
authored
Merge pull request #6 from kolchfa-aws/issue-workflow
Issue workflow
2 parents e6c82df + 30aeef0 commit ff4b713

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Check for issue for blogs
2+
3+
on:
4+
pull_request:
5+
types: [opened]
6+
paths:
7+
- '_posts/**'
8+
9+
permissions:
10+
pull-requests: write
11+
12+
jobs:
13+
check-linked-issues:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Check if PR adds new blog
18+
id: check-new-blog
19+
run: |
20+
files_added=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
21+
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" \
22+
| jq -r '.[] | select(.status == "added" and (.filename | startswith("_posts/"))) | .filename')
23+
24+
if [ ! -z "$files_added" ]; then
25+
echo "is_new_blog=true" >> $GITHUB_OUTPUT
26+
else
27+
echo "is_new_blog=false" >> $GITHUB_OUTPUT
28+
fi
29+
30+
- name: Get PR body
31+
if: steps.check-new-blog.outputs.is_new_blog == 'true'
32+
id: pr-body
33+
run: |
34+
body="${{ github.event.pull_request.body }}"
35+
echo "body=${body}" >> $GITHUB_OUTPUT
36+
37+
- name: Check for linked issues
38+
if: steps.check-new-blog.outputs.is_new_blog == 'true'
39+
id: check-issues
40+
run: |
41+
body="${{ github.event.pull_request.body }}"
42+
if echo "$body" | grep -iE "(closes|fixes|resolves|references|ref|close|fix|resolve) #[0-9]+"; then
43+
echo "has_issue=true" >> $GITHUB_OUTPUT
44+
else
45+
echo "has_issue=false" >> $GITHUB_OUTPUT
46+
fi
47+
48+
- name: Comment if no linked issue
49+
if: steps.check-new-blog.outputs.is_new_blog == 'true' && steps.check-issues.outputs.has_issue == 'false'
50+
uses: peter-evans/create-or-update-comment@v3
51+
with:
52+
token: ${{ secrets.GITHUB_TOKEN }}
53+
issue-number: ${{ github.event.pull_request.number }}
54+
body: |
55+
Hi @${{ github.event.pull_request.user.login }},
56+
57+
Looks like you're adding a new blog post and you don't have an issue mentioned. Please link this PR to an open issue using one of these keywords in the PR description:
58+
- Closes #issue-number
59+
- Fixes #issue-number
60+
- Resolves #issue-number
61+
62+
If there isn't an issue yet, please [create one](https://github.com/opensearch-project/project-website/issues/new?template=blog_post.yml) and then link it to this PR.

0 commit comments

Comments
 (0)