Added plugin logic
This commit is contained in:
parent
77279b3a99
commit
3a9dc6e261
55
plugin.sh
Normal file
55
plugin.sh
Normal file
@ -0,0 +1,55 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
|
||||
if [ "${PLUGIN_DOMAIN:-null}" = null ]; then
|
||||
echo "No gitea domain provided";
|
||||
exit 1;
|
||||
fi
|
||||
if [ "${PLUGIN_APIKEY:-null}" = null ]; then
|
||||
echo "No api key provided";
|
||||
exit 2;
|
||||
fi
|
||||
if [ "${PLUGIN_SOURCE:-null}" = null ]; then
|
||||
echo "No source branch provided, falling back to branch that triggered ci";
|
||||
exit 3;
|
||||
fi
|
||||
if [ "${PLUGIN_TARGET:-null}" = null ]; then
|
||||
echo "No target branch provided";
|
||||
exit 4;
|
||||
fi
|
||||
if [ "${PLUGIN_TITLE:-null}" = null ]; then
|
||||
PLUGIN_TITLE="$PLUGIN_SOURCE -> $PLUGIN_TARGET";
|
||||
fi
|
||||
|
||||
RES=$(curl --request POST \
|
||||
--url "https://$PLUGIN_DOMAIN/api/v1/repos/$DRONE_REPO/pulls" \
|
||||
--header "Content-Type: application/json" \
|
||||
--header "Authorization: token $APIKEY" \
|
||||
-F \
|
||||
--data "{
|
||||
\"title\": \"$PLUGIN_TITLE\",
|
||||
\"body\": \"Automatic merge of $PLUGIN_SOURCE into $PLUGIN_TARGET\",
|
||||
\"base\": \"$PLUGIN_TARGET\",
|
||||
\"head\": \"$PLUGIN_SOURCE\"
|
||||
}")
|
||||
echo "PR created";
|
||||
|
||||
if [ "${PLUGIN_MERGE:-false}" = true ]; then
|
||||
if [ "${PLUGIN_DELETE_SOURCE:-null}" = null ]; then
|
||||
echo "Falling back to not deleting source";
|
||||
PLUGIN_DELETE_SOURCE=false;
|
||||
fi
|
||||
|
||||
curl --request POST \
|
||||
--url "https://$PLUGIN_DOMAIN/api/v1/repos/$DRONE_REPO/pulls/$ID/merge" \
|
||||
--header 'Content-Type: application/json' \
|
||||
--header "Authorization: token $APIKEY" \
|
||||
-F \
|
||||
--data "{
|
||||
\"do\": \"merge\",
|
||||
\"delete_branch_after_merge\": $PLUGIN_DELETE_SOURCE
|
||||
}"
|
||||
echo "PR merged";
|
||||
fi
|
Loading…
x
Reference in New Issue
Block a user