Skip to content

Commit a4aeb15

Browse files
committed
Update hiring workflow
1 parent 1d1089c commit a4aeb15

File tree

1 file changed

+77
-17
lines changed

1 file changed

+77
-17
lines changed

.github/workflows/hiring-mirror-and-delete.yml

Lines changed: 77 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,26 @@ permissions:
1010

1111
jobs:
1212
mirror-and-delete:
13-
# Only act on issues created from the website
14-
if: ${{ startsWith(github.event.issue.title, 'Hiring Application from website') }}
13+
# Only act on issues created from the website (title set by your JS)
14+
if: ${{ startsWith(github.event.issue.title, 'Application from website') }}
1515
runs-on: ubuntu-latest
1616

1717
steps:
1818
- name: Install jq
1919
run: sudo apt-get update && sudo apt-get install -y jq
2020

21-
- name: Mirror to private repo and delete public issue
21+
- name: Mirror to private repo (with duplicate check) and delete public issue
2222
env:
2323
GH_TOKEN: ${{ secrets.HIRING_REPO_TOKEN }}
24+
25+
# Source: public site repo
2426
SOURCE_OWNER: platformbuilds
2527
SOURCE_REPO: platformbuilds.github.io
28+
29+
# Target: private hiring repo
2630
TARGET_OWNER: platformbuilds
2731
TARGET_REPO: hiring
32+
2833
ISSUE_NUMBER: ${{ github.event.issue.number }}
2934
run: |
3035
set -euo pipefail
@@ -45,27 +50,82 @@ jobs:
4550
echo "Source author: $author"
4651
echo "Source node_id: $node_id"
4752
48-
private_body=$(cat <<EOF
49-
Application submitted via website → public intake issue → mirrored by GitHub Actions.
53+
echo "Checking for existing open applications in ${TARGET_OWNER}/${TARGET_REPO} for @${author}…"
5054
51-
**Original author:** @${author}
52-
**Original issue (now deleted):** https://github.com/${SOURCE_OWNER}/${SOURCE_REPO}/issues/${ISSUE_NUMBER}
55+
# Build search query: repo:TARGET_OWNER/TARGET_REPO is:issue is:open "Original author: @author"
56+
encoded_query=$(printf 'repo:%s/%s is:issue is:open "Original author: @%s"' "$TARGET_OWNER" "$TARGET_REPO" "$author" | jq -sRr @uri)
5357
54-
---
55-
56-
${body}
57-
EOF
58-
)
58+
search_resp=$(curl -sSL \
59+
-H "Authorization: Bearer ${GH_TOKEN}" \
60+
-H "Accept: application/vnd.github+json" \
61+
"https://api.github.com/search/issues?q=${encoded_query}")
62+
63+
open_count=$(echo "$search_resp" | jq -r '.total_count')
64+
65+
echo "Open applications found for @${author}: ${open_count}"
66+
67+
if [ "$open_count" -gt 0 ]; then
68+
echo "Existing open application detected. Marking this intake issue as duplicate and NOT mirroring."
69+
70+
duplicate_body="We detected that you already have an open application with us linked to your GitHub account (@${author}). Please wait for that application to be processed before submitting another. If you believe this is an error, contact us at [email protected]."
5971
60-
create_payload=$(jq -n \
61-
--arg title "$title" \
62-
--arg body "$private_body" \
72+
update_payload=$(jq -n \
73+
--arg body "$duplicate_body" \
6374
'{
64-
title: $title,
6575
body: $body,
66-
labels: ["candidate", "source:public-intake"]
76+
state: "closed"
6777
}')
6878
79+
echo "Updating source issue #${ISSUE_NUMBER} as duplicate and closing…"
80+
81+
curl -sSL \
82+
-X PATCH \
83+
-H "Authorization: Bearer ${GH_TOKEN}" \
84+
-H "Accept: application/vnd.github+json" \
85+
"https://api.github.com/repos/${SOURCE_OWNER}/${SOURCE_REPO}/issues/${ISSUE_NUMBER}" \
86+
-d "$update_payload"
87+
88+
# Optional: add a comment too (user will get a notification)
89+
comment_payload=$(jq -n \
90+
--arg msg "We detected an existing open application associated with @${author}. We won't create a new one until the current application is closed in our internal system." \
91+
'{body: $msg}')
92+
93+
echo "Commenting on source issue to inform candidate…"
94+
95+
curl -sSL \
96+
-X POST \
97+
-H "Authorization: Bearer ${GH_TOKEN}" \
98+
-H "Accept: application/vnd.github+json" \
99+
"https://api.github.com/repos/${SOURCE_OWNER}/${SOURCE_REPO}/issues/${ISSUE_NUMBER}/comments" \
100+
-d "$comment_payload"
101+
102+
echo "Duplicate handling complete. Not mirroring; not deleting this intake issue (it is closed and scrubbed)."
103+
exit 0
104+
fi
105+
106+
echo "No existing open applications for @${author}. Proceeding to mirror."
107+
108+
private_body=$(cat <<EOF
109+
Application submitted via website → public intake issue → mirrored by GitHub Actions.
110+
111+
**Origin al author:** @${author}
112+
**Origin al issue (now deleted):** https://github.com/${SOURCE_OWNER}/${SOURCE_REPO}/issues/${ISSUE_NUMBER}
113+
114+
---
115+
116+
${body}
117+
EOF
118+
)
119+
120+
create_payload=$(jq -n \
121+
--arg title "$title" \
122+
--arg body "$private_body" \
123+
'{
124+
title: $title,
125+
body: $body,
126+
labels: ["candidate", "source:public-intake"]
127+
}')
128+
69129
echo "Creating issue in ${TARGET_OWNER}/${TARGET_REPO}…"
70130
71131
create_resp=$(curl -sSL \

0 commit comments

Comments
 (0)