-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: installs glab and adds functions to manage gitlab repos
This PR adds the installation of the glab tool and functions to handle gitlab repos. Relates to hacbs-release/app-interface-deployments#30
- Loading branch information
1 parent
7c19cfb
commit 4d9f4a6
Showing
3 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env sh | ||
# | ||
# Functions to manage git repositories | ||
|
||
git_functions_usage() { | ||
echo -e "Usage:" | ||
echo -e "\t~$ export GIT_AUTHOR_NAME=<name>" | ||
echo -e "\t~$ export GIT_AUTHOR_EMAIL=<email>" | ||
echo -e "\t~$ export ACCESS_TOKEN=<github key>" | ||
echo -e "\t~$ . git-functions" | ||
} | ||
|
||
git_config_ident() { | ||
git config user.name "${GIT_AUTHOR_NAME}" | ||
git config user.email "${GIT_AUTHOR_EMAIL}" | ||
} | ||
|
||
git_commit_and_push() { | ||
OPTIONS=$(getopt -l "branch:,message:" -o "b:m:" -a -- "$@") | ||
eval set -- "$OPTIONS" | ||
while true; do | ||
case "$1" in | ||
-b|--branch) | ||
shift | ||
BRANCH=$1 | ||
;; | ||
-m|--message) | ||
shift | ||
COMMIT_MSG="$1" | ||
;; | ||
--) | ||
shift | ||
break | ||
;; | ||
esac | ||
shift | ||
done | ||
git checkout -b $BRANCH | ||
git_config_ident | ||
git commit -a -m "$COMMIT_MSG" | ||
git push origin $BRANCH | ||
} | ||
|
||
git_clone_and_checkout() { | ||
OPTIONS=$(getopt -l "repository:,revision:" -o "r:v:" -a -- "$@") | ||
eval set -- "$OPTIONS" | ||
while true; do | ||
case "$1" in | ||
-r|--repository) | ||
shift | ||
REPOSITORY=$1 | ||
;; | ||
-v|--revision) | ||
shift | ||
REVISION="$1" | ||
;; | ||
--) | ||
shift | ||
break | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
echo "Cloning the Repository..." | ||
|
||
REPO_DIR=$(basename ${REPOSITORY} .git) | ||
|
||
# rewrites the repo url with the auth token | ||
CLONE_URL="https://oauth2:${ACCESS_TOKEN}@${REPO_URL#*://}" | ||
git clone $CLONE_URL | ||
cd $REPO_DIR | ||
git checkout $REVISION | ||
} | ||
|
||
git_functions_init() { | ||
# an actual user should be set | ||
[ -z "${GIT_AUTHOR_NAME}" -o -z "${GIT_AUTHOR_EMAIL}" ] && git_functions_usage && return 1 | ||
|
||
# it should not continue if ACCESS_TOKEN | ||
[ -z "${ACCESS_TOKEN}" ] && git_functions_usage && return 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env sh | ||
# | ||
# Functions to manage gitlab repos. | ||
# | ||
# This library requires the `glab` cli (https://docs.gitlab.com/ee/integration/glab/) | ||
|
||
gitlab_usage() { | ||
echo -e "Usage:" | ||
echo -e "\t~$ export GITLAB_HOST=<host>" | ||
echo -e "\t~$ export ACCESS_TOKEN=<github key>" | ||
echo -e "\t~$ . gitlab-functions" | ||
} | ||
|
||
gitlab_auth() { | ||
gitlab_host=$1 | ||
glab auth login -h $gitlab_host --stdin <<< "${ACCESS_TOKEN}" | ||
} | ||
|
||
gitlab_create_mr() { | ||
OPTIONS=$(getopt -l "head:,title:,description:" -o "h:t:d:" -a -- "$@") | ||
eval set -- "$OPTIONS" | ||
while true; do | ||
case "$1" in | ||
-h|--head) | ||
shift | ||
HEAD="$1"; | ||
;; | ||
-t|--title) | ||
shift | ||
TITLE="$1"; | ||
;; | ||
-d|--description) | ||
shift | ||
DESCRIPTION="$1"; | ||
;; | ||
--) | ||
shift | ||
break | ||
;; | ||
esac | ||
shift | ||
done | ||
glab mr create --title "${TITLE}" -b ${HEAD} --description "${DESCRIPTION}" | \ | ||
awk '/merge_request/ {print "merge_request: "$1}' |yq -o json | ||
} | ||
|
||
gitlab_init() { | ||
# it should not continue if ACCESS_TOKEN or GITLAB_HOST is missing | ||
[ -z "${ACCESS_TOKEN}" -o -z "${GITLAB_HOST}" ] && gitlab_usage && return 1 | ||
|
||
gitlab_auth ${GITLAB_HOST} | ||
} |