0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Shell Scripting GITLAB API

Last updated at Posted at 2024-11-27

GITLAB APIに接続するシェルスクリプトを作る。

方針

必要な情報を取得してプログラムを書く。
・プロジェクトIDを取得
・TOKENを設定して取得
・環境変数を設定
・シェルスクリプトを書く

プロジェクトIDを取得

プロジェクトIDは以下から取得できる。この場合は2である。

Screenshot_2024-11-28_01-21-54.png

TOKENを設定して取得

アイコン>Preferences

Screenshot_2024-11-28_01-20-58.png

Access tokens> Add new token

Screenshot_2024-11-28_01-24-06.png

適当に名前を決めてAPIをクリックしてからCreate personal access tokenをクリック

Screenshot_2024-11-28_01-25-42.png

ACCESS TOKENが取得できた。今回はglpat-s7oEDZwxNoRDJ_-S9USy

Screenshot_2024-11-28_03-45-58.png

環境変数を設定

環境変数のためのファイル

.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}]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?