|
| 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 update_gitlab_pullrequest() { |
| 11 | + local pr |
| 12 | + local REPO |
| 13 | + local OWNER |
| 14 | + local up_pr_title |
| 15 | + local up_pr_body |
| 16 | + local payload |
| 17 | + local endpoint |
| 18 | + local response |
| 19 | + |
| 20 | + # Pull Request number |
| 21 | + pr="$1" |
| 22 | + |
| 23 | + # Verifica se o parâmetro foi fornecido |
| 24 | + if [[ -z "$pr" ]]; then |
| 25 | + echo "Pull Request number is required." |
| 26 | + exit 1 |
| 27 | + fi |
| 28 | + |
| 29 | + # Name of repository |
| 30 | + REPO="$2" |
| 31 | + |
| 32 | + # Verifica se o parâmetro foi fornecido |
| 33 | + if [[ -z "$REPO" ]]; then |
| 34 | + # Se não foi fornecido, utiliza o nome do diretório atual |
| 35 | + REPO=$(basename "$PWD") |
| 36 | + fi |
| 37 | + |
| 38 | + # Repo owner |
| 39 | + OWNER="$3" |
| 40 | + |
| 41 | + # Verifica se o parâmetro foi fornecido |
| 42 | + if [[ -z "$OWNER" ]]; then |
| 43 | + # Se não foi fornecido, utiliza o padrão definido em auth.sh |
| 44 | + OWNER="$DEF_GH_OWNER" |
| 45 | + fi |
| 46 | + |
| 47 | + pr_title="$(format_pullrequest "title")" |
| 48 | + pr_body="$(format_pullrequest "body")" |
| 49 | + |
| 50 | + # Create the JSON payload for the repository |
| 51 | + payload='{"title":"'"$pr_title"'", "body":"'"$pr_body"'"}' |
| 52 | + |
| 53 | + # Construct the endpoint URL |
| 54 | + pr_endpoint="$(build_gl_endpoint "PR" "$OWNER" "$REPO")" |
| 55 | + endpoint="$pr_endpoint/$pr" |
| 56 | + |
| 57 | + # Create the repository using curl |
| 58 | + response=$(curl -sSL -X PATCH "$endpoint" \ |
| 59 | + -H "Content-Type: application/json" \ |
| 60 | + -H "Authorization: Bearer $GITLAB_TOKEN" \ |
| 61 | + -d "$payload" ) |
| 62 | + |
| 63 | + # Check if there are erros |
| 64 | + echo "$response" | jq -r '.number // .message' |
| 65 | +} |
| 66 | + |
| 67 | +update_gitlab_pullrequest "$1" "$2" "$3" |
0 commit comments