Skip to content

Commit 3377f9d

Browse files
committed
Gitlab merge pull request
1 parent 9b7fc4b commit 3377f9d

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/gitlab/gl-pr-merge.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
3+
# Authentication and default settings
4+
source "$GITNAP/utils/auth.sh"
5+
source "$GITNAP/utils/endpoints.sh"
6+
source "$GITNAP/utils/settings.sh"
7+
source "$GITNAP/utils/format_pullrequest.sh"
8+
9+
10+
function merge_gitlab_pullrequest() {
11+
local pr
12+
local REPO
13+
local OWNER
14+
local payload
15+
local endpoint
16+
local response
17+
18+
# Pull Request number
19+
pr="$1"
20+
21+
# Verifica se o parâmetro foi fornecido
22+
if [[ -z "$pr" ]]; then
23+
echo "Pull Request number is required."
24+
exit 1
25+
fi
26+
27+
# Name of repository
28+
REPO="$2"
29+
30+
# Verifica se o parâmetro foi fornecido
31+
if [[ -z "$REPO" ]]; then
32+
# Se não foi fornecido, utiliza o nome do diretório atual
33+
REPO=$(basename "$PWD")
34+
fi
35+
36+
# Repo owner
37+
OWNER="$3"
38+
39+
# Verifica se o parâmetro foi fornecido
40+
if [[ -z "$OWNER" ]]; then
41+
# Se não foi fornecido, utiliza o padrão definido em auth.sh
42+
OWNER="$DEF_GH_OWNER"
43+
fi
44+
45+
# Create the JSON payload for the repository
46+
payload='{"merge_method":"squash"}'
47+
48+
# Construct the endpoint URL
49+
pr_endpoint="$(build_gl_endpoint "PR" "$OWNER" "$REPO")"
50+
endpoint="$pr_endpoint/$pr/merge"
51+
52+
# Create the repository using curl
53+
response=$(curl -sSL -X PUT "$endpoint" \
54+
-H "Content-Type: application/json" \
55+
-H "Authorization: Bearer $GITLAB_TOKEN" \
56+
-d "$payload" )
57+
58+
# Check if there are erros
59+
echo "$response" #| jq -r '.number // .message'
60+
}
61+
62+
merge_gitlab_pullrequest "$1" "$2" "$3"

0 commit comments

Comments
 (0)