LoginSignup
4
4

More than 5 years have passed since last update.

GitLab API | gitlab gem で Issueの編集

Posted at

GitLab API | gitlab gem で Issueの編集

概要

gitlab gem で Issueの編集

シグネチャ

edit_issue(project, id, options = {})

project は プロジェクトの id
id は Issue の id
(※プロジェクトごとの連番になっている Issue.iid ではないので注意。GitLab の画面に表示されているのは iid。
ここで利用するのはプロジェクトを問わず全体の連番になっている Issue.id)

option type 内容
:title String Issueのタイトル
:description String Issueの内容。Markdownで記述
:assignee_id Integer アサイン先のid
:milestone_id Integer マイルストーンのid
:labels String カンマ区切りのラベル名のリスト
:state_event String ステータス。'close' か 'reopen'

サンプル

新規作成

項目 設定値
project_id 31
title new_title
description new_description
assignee_id 1
labels ruby,gitlab

※stateは opend になる。

編集内容

項目 設定値
project_id 31
title edit_title
description edit_description
assignee_id 4
state_event close
labels perl,github

コード

require 'gitlab'
require 'tbpgr_utils'

def show_issue_detail(issue, message_header = '')
  assignee_id = issue.assignee ? issue.assignee.id : ''
  puts message_header
  bulk_puts_eval binding, <<-EOS
issue.id
issue.iid
issue.project_id
issue.title
issue.description
assignee_id
issue.state
issue.labels
  EOS
end

Gitlab.configure do |config|
  config.endpoint       = 'http://some_path/api/v3' 
  config.private_token  = 'some token'
end
project_id = 31
Gitlab.create_issue(project_id, 'new_title', description: 'new_description', assignee_id: 1, labels: 'ruby,gitlab')
new_issue = Gitlab.issues(project_id).first
show_issue_detail(new_issue, "-------new record-------")
Gitlab.edit_issue(project_id, new_issue.id, title:'edit_title', description: 'edit_description', assignee_id: 4, state_event: 'close', labels: 'perl,github')
edit_issue = Gitlab.issues(project_id).first
show_issue_detail(edit_issue, "-------edit record-------")

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils

出力

-------new record-------
issue.id          # => 90
issue.iid         # => 13
issue.project_id  # => 31
issue.title       # => "new_title"
issue.description # => "new_description"
assignee_id       # => 1
issue.state       # => "opened"
issue.labels      # => ["ruby", "gitlab"]
-------edit record-------
issue.id          # => 90
issue.iid         # => 13
issue.project_id  # => 31
issue.title       # => "edit_title"
issue.description # => "edit_description"
assignee_id       # => 4
issue.state       # => "closed"
issue.labels      # => ["perl", "github"]

参照

4
4
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
4
4