-
Notifications
You must be signed in to change notification settings - Fork 32
48 lines (39 loc) · 1.66 KB
/
approve_new_port.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
name: Create New Port Repository
permissions:
contents: write
issues: write
actions: read
on:
issues:
types: [labeled]
jobs:
create-repo:
if: github.event.label.name == 'approved'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Extract Port Name
run: |
echo "PORT_NAME=$(echo "${GITHUB_EVENT_ISSUE_TITLE}" | cut -d: -f2- | tr -d ' ' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
env:
GITHUB_EVENT_ISSUE_TITLE: ${{ github.event.issue.title }}
- name: Check if Repository Exists
env:
ORGANIZATION: zopencommunity
GH_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }}
PORT_NAME: ${{ env.PORT_NAME }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
run: |
REPO_NAME="${PORT_NAME}port"
if gh repo view "$ORGANIZATION/$REPO_NAME" &> /dev/null; then
echo "Repository '$ORGANIZATION/$REPO_NAME' already exists."
gh issue comment "$ISSUE_NUMBER" --repo "$ORGANIZATION/meta" --body "Repository already exists: https://github.com/$ORGANIZATION/$REPO_NAME"
exit 1
else
echo "Repository '$ORGANIZATION/$REPO_NAME' does not exist. Proceeding to create it."
gh repo create "$ORGANIZATION/$REPO_NAME" --public
# Assign the issue creator as the admin
gh api --method PUT "repos/$ORGANIZATION/$REPO_NAME/collaborators/${{ github.event.issue.user.login }}" -f permission=admin
# Comment on an issue
gh issue comment "$ISSUE_NUMBER" --repo "$ORGANIZATION/meta" --body "Repository created: https://github.com/$ORGANIZATION/$REPO_NAME"
fi