Skip to content

Commit bac4746

Browse files
authored
Create sync_issue_github-codeberg.yml
1 parent 877e473 commit bac4746

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Issue sync (GitHub -> Codeberg Forgejo)
2+
on:
3+
issues:
4+
types: [opened, deleted, pinned, unpinned, closed, reopened, assigned, unassigned, labeled, unlabeled, locked, unlocked, milestoned, demilestoned]
5+
issue_comment:
6+
types: [created]
7+
8+
jobs:
9+
sync:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: GitHub -> Forgejo Issue sync
13+
run: |
14+
URL='https://codeberg.org/'
15+
REPO='movingpandas/trajectools'
16+
TOKEN=${{ secrets._CODEBERG_TOKEN }}
17+
18+
sync=0
19+
20+
echo "Issue body: ${{ github.event.issue.body }}"
21+
echo "Comment body: ${{ github.event.comment.body }}"
22+
echo "Event Name: ${{ github.event_name }}"
23+
echo "Type: ${{ github.event.action }}"
24+
25+
##################### Issue #####################
26+
if [ "${{ github.event_name }}" == 'issues' ]; then
27+
28+
case "${{ github.event.action }}" in
29+
30+
opened) #### OPENED ####
31+
if [[ "${{ github.event.issue.body }}" == "<p><table><tr><th><details><summary></summary>This is an issue created by automatic synchronization.</details>"* ]]; then
32+
echo "Already synchronized - nothing to do"
33+
sync=1
34+
else
35+
data="{
36+
\"title\": \"${{ github.event.issue.title }}\",
37+
\"body\": \"
38+
<p>
39+
<table>
40+
<tr>
41+
<th>
42+
<details><summary></summary>
43+
This is an issue created by automatic synchronization.
44+
</details>
45+
</th>
46+
<th>
47+
<a href='https://github.com/${{ github.event.issue.user.login }}'>
48+
<img src='https://github.com/${{ github.event.issue.user.login }}.png' width='25'></a>
49+
</th>
50+
<th>
51+
<a href='https://github.com/${{ github.event.issue.user.login }}'>${{ github.event.issue.user.login }}</a> commented on GitHub
52+
</th>
53+
<th>
54+
<a href='https://github.com/${{ github.repository }}/issues/${{ github.event.issue.number }}'>Link to the issue</a>
55+
</th>
56+
</tr>
57+
</table>
58+
</p>
59+
60+
${{ github.event.comment.body }}
61+
\"
62+
}"
63+
64+
url=$URL"api/v1/repos/"$REPO"/issues"
65+
fi
66+
;;
67+
68+
closed) #### CLOSED ####
69+
echo "Closed issue"
70+
;;
71+
72+
labeled) #### LABELED ####
73+
echo "Labeled issue"
74+
;;
75+
76+
unlabeled) #### UNLABELED ####
77+
echo "Unalbeled"
78+
;;
79+
80+
*)
81+
echo "Other type: ${{ github.event.action }}"
82+
;;
83+
esac
84+
85+
86+
##################### Issue comment #####################
87+
elif [ "${{ github.event_name }}" == 'issue_comment' ]; then
88+
if [[ "${{ github.event.comment.body }}" == "<p><table><tr><th><details><summary></summary>This is an issue created by automatic synchronization.</details>"* ]]; then
89+
echo "Already synchronized - nothing to do"
90+
sync=1
91+
else
92+
echo "Creating Issue Comment"
93+
data="{\"title\": \"Issue-Comment\", \"body\": \"<p><table><tr><th><details><summary></summary>This is an issue created by automatic synchronization.</details></th><th><a href='https://github.com/${{ github.event.comment.user.login }}'><img src='https://github.com/${{ github.event.comment.user.login }}.png' width='25'></a></th><th><a href='https://github.com/${{ github.event.comment.user.login }}'>${{ github.event.comment.user.login }}</a> commented on GitHub</th><th><a href='https://github.com/${{ github.repository }}/issues/${{ github.event.issue.number }}'>Link to the issue</a></th></tr></table></p>${{ github.event.comment.body }}\"}"
94+
url=$URL"api/v1/repos/"$REPO"/issues/${{ github.event.issue.number }}/comments"
95+
fi
96+
fi
97+
98+
99+
##################### Finally send request #####################
100+
if [[ $sync == 1 ]]; then
101+
echo "curl --> Already synchronized"
102+
else
103+
echo "::group::curl info"
104+
echo "url: $url"
105+
echo "data: $data"
106+
echo "::endgroup::"
107+
curl -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" -d "$data" $url
108+
fi

0 commit comments

Comments
 (0)