Skip to content

Issue sync (GitHub -> Codeberg Forgejo) #9

Issue sync (GitHub -> Codeberg Forgejo)

Issue sync (GitHub -> Codeberg Forgejo) #9

name: Issue sync (GitHub -> Codeberg Forgejo)
on:
issues:
types: [opened, deleted, pinned, unpinned, closed, reopened, assigned, unassigned, labeled, unlabeled, locked, unlocked, milestoned, demilestoned]
issue_comment:
types: [created]
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: GitHub -> Forgejo Issue sync
run: |
URL='https://codeberg.org/'
REPO='movingpandas/trajectools'
TOKEN=${{ secrets._CODEBERG_TOKEN }}
sync=0
echo "Issue body: ${{ github.event.issue.body }}"
echo "Comment body: ${{ github.event.comment.body }}"
echo "Event Name: ${{ github.event_name }}"
echo "Type: ${{ github.event.action }}"
##################### Issue #####################
if [ "${{ github.event_name }}" == 'issues' ]; then
case "${{ github.event.action }}" in
opened) #### OPENED ####
if [[ "${{ github.event.issue.body }}" == "<p><table><tr><th><details><summary></summary>This is an issue created by automatic synchronization.</details>"* ]]; then
echo "Already synchronized - nothing to do"
sync=1
else
data="{
\"title\": \"${{ github.event.issue.title }}\",
\"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.issue.user.login }}'>
<img src='https://github.com/${{ github.event.issue.user.login }}.png' width='25'></a>
</th>
<th>
<a href='https://github.com/${{ github.event.issue.user.login }}'>${{ github.event.issue.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 }}
\"
}"
url=$URL"api/v1/repos/"$REPO"/issues"
fi
;;
closed) #### CLOSED ####
echo "Closed issue"
;;
labeled) #### LABELED ####
echo "Labeled issue"
;;
unlabeled) #### UNLABELED ####
echo "Unalbeled"
;;
*)
echo "Other type: ${{ github.event.action }}"
;;
esac
##################### Issue comment #####################
elif [ "${{ github.event_name }}" == 'issue_comment' ]; then
if [[ "${{ github.event.comment.body }}" == "<p><table><tr><th><details><summary></summary>This is an issue created by automatic synchronization.</details>"* ]]; then
echo "Already synchronized - nothing to do"
sync=1
else
echo "Creating Issue Comment"
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 }}\"}"
url=$URL"api/v1/repos/"$REPO"/issues/${{ github.event.issue.number }}/comments"
fi
fi
##################### Finally send request #####################
if [[ $sync == 1 ]]; then
echo "curl --> Already synchronized"
else
echo "::group::curl info"
echo "url: $url"
echo "data: $data"
echo "::endgroup::"
curl -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" -d "$data" $url
fi