Skip to content

Commit 3c3be3d

Browse files
authored
Merge pull request opensearch-project#3806 from kolchfa-aws/issue-workflow
Add a workflow to check for open issue
2 parents e6c82df + 547ce0b commit 3c3be3d

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Process a new blog
2+
3+
on:
4+
pull_request_target:
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: Add blog process comment
31+
if: steps.check-new-blog.outputs.is_new_blog == 'true'
32+
uses: peter-evans/create-or-update-comment@v3
33+
with:
34+
token: ${{ secrets.GITHUB_TOKEN }}
35+
issue-number: ${{ github.event.pull_request.number }}
36+
body: |
37+
Thank you for submitting a blog post!
38+
39+
The blog post review process is: Submit a PR -> (Optional) Peer review -> Doc review -> Editorial review -> Marketing review -> Published.
40+
41+
- name: Check for linked issues
42+
if: steps.check-new-blog.outputs.is_new_blog == 'true'
43+
id: check-issues
44+
run: |
45+
echo "${{ github.event.pull_request.body }}" > pr_body.txt
46+
if grep -iE "(closes|fixes|resolves|references|ref|close|fix|resolve) #[0-9]+" pr_body.txt > /dev/null; then
47+
echo "has_issue=true" >> $GITHUB_OUTPUT
48+
else
49+
echo "has_issue=false" >> $GITHUB_OUTPUT
50+
fi
51+
rm pr_body.txt
52+
53+
- name: Comment if no linked issue
54+
if: steps.check-new-blog.outputs.is_new_blog == 'true' && steps.check-issues.outputs.has_issue == 'false'
55+
uses: peter-evans/create-or-update-comment@v3
56+
with:
57+
token: ${{ secrets.GITHUB_TOKEN }}
58+
issue-number: ${{ github.event.pull_request.number }}
59+
body: |
60+
Hi @${{ github.event.pull_request.user.login }},
61+
62+
It looks like you're adding a new blog post but don't have an issue mentioned. Please link this PR to an open issue using one of these keywords in the PR description:
63+
- Closes #issue-number
64+
- Fixes #issue-number
65+
- Resolves #issue-number
66+
67+
If an issue hasn't been created 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)