Skip to content

Commit

Permalink
Added support for GitLab
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas committed Nov 1, 2023
1 parent 0d511ba commit f4b4da5
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 1 deletion.
15 changes: 15 additions & 0 deletions hooks/common/post-flow-feature-publish
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ elif [[ $ORIGIN_URL =~ ^https://.*bitbucket\.org ]]; then
}
EOM
die_on_error "Failed to create a Pull Request"
elif [[ $ORIGIN_URL =~ ^git@gitlab\.com ]]; then
repo=$(echo $ORIGIN_URL | sed -e 's/^git@gitlab\.com://' -e 's/\.git$//')
if command -v glab &> /dev/null; then
glab mr create \
--title "Merge $BRANCH" \
--description "Feature $VERSION. Do not delete the feature branch after the merge." \
--source-branch $BRANCH \
--target-branch $DEVELOP_BRANCH \
--yes
else
echo ""
echo "Create Pull Request at: https://gitlab.com/$repo/-/merge_requests/new"
echo "Do not delete the feature branch after the Pull Request is merged. It will be deleted automatically when the feature is finished."
echo ""
fi
else
echo "Create a Pull Request manually at $ORIGIN_URL"
echo "Do not delete the feature branch after the Pull Request is merged. It will be deleted automatically when the feature is finished."
Expand Down
15 changes: 15 additions & 0 deletions hooks/common/post-flow-hotfix-publish
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ elif [[ $ORIGIN_URL =~ ^https://.*bitbucket\.org ]]; then
}
EOM
die_on_error "Failed to create a Pull Request"
elif [[ $ORIGIN_URL =~ ^git@gitlab\.com ]]; then
repo=$(echo $ORIGIN_URL | sed -e 's/^git@gitlab\.com://' -e 's/\.git$//')
if command -v glab &> /dev/null; then
glab mr create \
--title "Merge $BRANCH" \
--description "Hotfix $VERSION. Do not delete the hotfix branch after the merge." \
--source-branch $BRANCH \
--target-branch $MASTER_BRANCH \
--yes
else
echo ""
echo "Create Pull Request at: https://gitlab.com/$repo/-/merge_requests/new"
echo "Do not delete the feature branch after the Pull Request is merged. It will be deleted automatically when the feature is finished."
echo ""
fi
else
echo "Create a Pull Request manually at $ORIGIN_URL"
echo "Do not delete the hotfix branch after the Pull Request is merged. It will be deleted automatically when the hotfix is finished."
Expand Down
15 changes: 15 additions & 0 deletions hooks/common/post-flow-release-publish
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ elif [[ $ORIGIN_URL =~ ^https://.*bitbucket\.org ]]; then
}
EOM
die_on_error "Failed to create a Pull Request"
elif [[ $ORIGIN_URL =~ ^git@gitlab\.com ]]; then
repo=$(echo $ORIGIN_URL | sed -e 's/^git@gitlab\.com://' -e 's/\.git$//')
if command -v glab &> /dev/null; then
glab mr create \
--title "Merge $BRANCH" \
--description "Release $VERSION. Do not delete the release branch after the merge." \
--source-branch $BRANCH \
--target-branch $MASTER_BRANCH \
--yes
else
echo ""
echo "Create Pull Request at: https://gitlab.com/$repo/-/merge_requests/new"
echo "Do not delete the feature branch after the Pull Request is merged. It will be deleted automatically when the feature is finished."
echo ""
fi
else
echo "Create a Pull Request manually at $ORIGIN_URL"
echo "Do not delete the release branch after the Pull Request is merged. It will be deleted automatically when the release is finished."
Expand Down
13 changes: 13 additions & 0 deletions hooks/common/pre-flow-feature-finish
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ elif [[ $ORIGIN_URL =~ ^https://.*bitbucket\.org ]]; then
verbose "Fetching ${DEVELOP_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${DEVELOP_BRANCH}:${DEVELOP_BRANCH}
die_on_error "Failed to fetch $DEVELOP_BRANCH from $ORIGIN"
elif [[ $ORIGIN_URL =~ ^git@gitlab\.com ]]; then
if command -v glab &> /dev/null; then
PR_STATE=$(glab mr view $BRANCH | awk '/^state:/{print $2}')
die_on_error "There is no Pull Request for branch $BRANCH, please publish this feature before finishing it."
if [[ $PR_STATE != merged ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${DEVELOP_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${DEVELOP_BRANCH}:${DEVELOP_BRANCH}
die_on_error "Failed to fetch $DEVELOP_BRANCH from $ORIGIN"
else
die "glab is not available, so I cannot check pull request states on $ORIGIN ($ORIGIN_URL)"
fi
else
die "$ORIGIN ($ORIGIN_URL) is not a github repository, so I cannot check pull request states"
fi
Expand Down
15 changes: 14 additions & 1 deletion hooks/common/pre-flow-hotfix-finish
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,26 @@ elif [[ $ORIGIN_URL =~ ^https://.*bitbucket\.org ]]; then
.values |= sort_by(.updated_on) |
last(.values[] | select(.source.branch.name == $BRANCH) | .state)'
)
die_on_error "There is no Pull Request for branch $BRANCH, please publish this release before finishing it."
die_on_error "There is no Pull Request for branch $BRANCH, please publish this hotfix before finishing it."
if [[ $PR_STATE != MERGED ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${MASTER_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
die_on_error "Failed to fetch $MASTER_BRANCH from $ORIGIN"
elif [[ $ORIGIN_URL =~ ^git@gitlab\.com ]]; then
if command -v glab &> /dev/null; then
PR_STATE=$(glab mr view $BRANCH | awk '/^state:/{print $2}')
die_on_error "There is no Pull Request for branch $BRANCH, please publish this hotfix before finishing it."
if [[ $PR_STATE != merged ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${MASTER_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
die_on_error "Failed to fetch $MASTER_BRANCH from $ORIGIN"
else
die "glab is not available, so I cannot check pull request states on $ORIGIN ($ORIGIN_URL)"
fi
else
die "$ORIGIN ($ORIGIN_URL) is not a github repository, so I cannot check pull request states"
fi
Expand Down
13 changes: 13 additions & 0 deletions hooks/common/pre-flow-release-finish
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ elif [[ $ORIGIN_URL =~ ^https://.*bitbucket\.org ]]; then
verbose "Fetching ${MASTER_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
die_on_error "Failed to fetch $MASTER_BRANCH from $ORIGIN"
elif [[ $ORIGIN_URL =~ ^git@gitlab\.com ]]; then
if command -v glab &> /dev/null; then
PR_STATE=$(glab mr view $BRANCH | awk '/^state:/{print $2}')
die_on_error "There is no Pull Request for branch $BRANCH, please publish this release before finishing it."
if [[ $PR_STATE != merged ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${MASTER_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
die_on_error "Failed to fetch $MASTER_BRANCH from $ORIGIN"
else
die "glab is not available, so I cannot check pull request states on $ORIGIN ($ORIGIN_URL)"
fi
else
die "$ORIGIN ($ORIGIN_URL) is not a github repository, so I cannot check pull request states"
fi
Expand Down

0 comments on commit f4b4da5

Please sign in to comment.