-
Notifications
You must be signed in to change notification settings - Fork 2
43 lines (37 loc) · 1.65 KB
/
match_target_repository.yaml
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
name: Update Repository URL
on:
pull_request_target:
jobs:
update-repo-url:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/[email protected]
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Update repository URL
env:
GITHUB_BASE_LOGIN: ${{ github.event.pull_request.base.repo.owner.login }}
GITHUB_BASE_REPO_NAME: ${{ github.event.pull_request.base.repo.name }}
GITHUB_REPO: ${{ github.event.pull_request.head.repo.full_name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HEAD_REF: ${{ github.head_ref }}
run: |
TARGET_REPO_URL="https://github.com/${GITHUB_BASE_LOGIN}/${GITHUB_BASE_REPO_NAME}"
# Update the repository field in pyproject.toml
if grep -q '^repository = ' pyproject.toml; then
echo "Updating repository URL in pyproject.toml..."
sed -i "s|^repository = \".*\"|repository = \"$TARGET_REPO_URL\"|" pyproject.toml
else
echo "Adding repository URL to pyproject.toml..."
echo "repository = \"$TARGET_REPO_URL\"" >> pyproject.toml
fi
# Commit and push changes
git config --local user.email "[email protected]"
git config --local user.name "🐈 Theodore"
git remote set-url --push origin "https://${GITHUB_TOKEN}@github.com/${GITHUB_REPO}"
git add pyproject.toml
git commit -m ":twisted_rightwards_arrows: Update repository URL to PR target." || exit 0
git push origin HEAD:"${HEAD_REF}"