Gitalb api

From I Will Fear No Evil
Jump to navigation Jump to search
Basic API Calls for Gitlab
curl -L "https://gitlab.iwillfearnoevil.com/api/v4/projects" | jq '.'

Partial return:
  {
    "id": 17,
    "description": "Find out all the things when invoked",
    "name": "discovery",
    "name_with_namespace": "monitoring / discovery",
    "path": "discovery",
    "path_with_namespace": "monitoring/discovery",
    "created_at": "2016-06-18T21:35:07.253Z",
    "default_branch": "master",
    "tag_list": [],
    "topics": [],
    "ssh_url_to_repo": "git@gitlab01.iwillfearnoevil.com:monitoring/discovery.git",
    "http_url_to_repo": "https://gitlab01.iwillfearnoevil.com/monitoring/discovery.git",
    "web_url": "https://gitlab01.iwillfearnoevil.com/monitoring/discovery",
    "readme_url": null,
    "avatar_url": null,
    "forks_count": 0,
    "star_count": 0,
    "last_activity_at": "2016-06-18T21:57:23.124Z",
    "namespace": {
      "id": 4,
      "name": "monitoring",
      "path": "monitoring",
      "kind": "group",
      "full_path": "monitoring",
      "parent_id": null,
      "avatar_url": null,
      "web_url": "https://gitlab01.iwillfearnoevil.com/groups/monitoring"
    }
  }
Working Example

This is using an APPLICATION PAT, not a user PAT. Issues seem to arise with user PAT. Likely issue with missed setting int GUI.

curl -s -q --request GET --header "PRIVATE-TOKEN: glpat-t5_6CE7Xz3sN1Kby_65H" -L "https://gitlab.iwillfearnoevil.com/api/v4/notification_settings" | jq '.'
{
  "level": "participating",
  "notification_email": "project56_bot@noreply.gitlab01.iwillfearnoevil.com"
}
Pulling Snippets
curl -s -q --request GET --header "PRIVATE-TOKEN: glpat-t5_6CE7Xz3sN1Kby_65H" -L "https://gitlab.iwillfearnoevil.com/api/v4/snippets/1" | jq '.'
{
  "id": 1,
  "title": "bash getopts",
  "description": null,
  "visibility": "public",
  "updated_at": "2016-06-19T02:20:53.011Z",
  "created_at": "2016-06-19T02:20:53.011Z",
  "project_id": null,
  "web_url": "https://gitlab01.iwillfearnoevil.com/-/snippets/1",
  "raw_url": "https://gitlab01.iwillfearnoevil.com/-/snippets/1/raw",
  "ssh_url_to_repo": "git@gitlab01.iwillfearnoevil.com:snippets/1.git",
  "http_url_to_repo": "https://gitlab01.iwillfearnoevil.com/snippets/1.git",
  "author": {
    "id": 2,
    "username": "chubbard",
    "name": "Chris Hubbard",
    "state": "active",
    "avatar_url": "https://secure.gravatar.com/avatar/cf780bb1a19cb5dc118c6b3c5a7e8f9c?s=80&d=identicon",
    "web_url": "https://gitlab01.iwillfearnoevil.com/chubbard"
  },
  "file_name": "snippetfile1.txt",
  "files": [
    {
      "path": "snippetfile1.txt",
      "raw_url": "https://gitlab01.iwillfearnoevil.com/-/snippets/1/raw/master/snippetfile1.txt"
    }
  ]
}
Gitlab Alerts
  1. Create a webhook in Project >> Settings >> Monitor >> Alerts
  2. You will need both the URL, AND the key
    1. Success returns json: [{"iid":2,"title":"Incident title"}]
    2. curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ${KEY}" -L ${URL} --data '@test.json'
      1. https://gitlab01.iwillfearnoevil.com/monitoring/slimframework/nmsApi/-/alert_management/2/details#/overview