GITLAB APIに接続するシェルスクリプトを作る。
方針
必要な情報を取得してプログラムを書く。
・プロジェクトIDを取得
・TOKENを設定して取得
・環境変数を設定
・シェルスクリプトを書く
プロジェクトIDを取得
プロジェクトIDは以下から取得できる。この場合は2である。
TOKENを設定して取得
アイコン>Preferences
Access tokens> Add new token
適当に名前を決めてAPIをクリックしてからCreate personal access tokenをクリック
ACCESS TOKENが取得できた。今回はglpat-s7oEDZwxNoRDJ_-S9USy
環境変数を設定
環境変数のためのファイル
.envrc
export GITLAB_URL=http://127.0.0.1
シェルスクリプト
gitlab-auth.sh
if [[ -z "${GITLAB_TOKEN}" ]]; then
echo "What is your Personal Access Token? (Note: Input will be hidden)"
read -s GITLAB_TOKEN
fi
if [[ -z "${GITLAB_URL}" ]]; then
echo "What is the URL of GitLab Server?"
read GITLAB_URL
fi
PROJECT_ID="2"
curl -k --silent \
${GITLAB_URL}/api/v4/projects/${PROJECT_ID}/repository/contributors?private_token=${GITLAB_TOKEN}
実行
$source .envrc
$chmod +x gitlab-auth.sh
$./gitlab-auth.sh
What is your Personal Access Token? (Note: Input will be hidden)
What is the URL of GitLab Server?
http://127.0.0.1
[{"name":"root","email":"root@localhost","commits":9,"additions":0,"deletions":0}]