Class: SupportOps::GitLab::Events

Inherits:
Base
  • Object
show all
Defined in:
lib/support_ops_gitlab/gitlab/events.rb

Overview

TODO:

Document attribute definitions

Defines the class Events within the module SupportOps::GitLab.

Author:

  • Jason Colyer

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

#activate!, #approve!, attributes, #badges, #ban!, #block!, client, #client=, #commits, configure, #contributors, #create_support_pin!, #deactivate!, define_attributes, #delete!, #disable_2fa!, #discussions, #emails, #encoded_path, #events, #find, #find!, #gpg_keys, #hard_delete!, #impersonations, #initialize, #issues, #jobs, #latest_pipeline, #members, #memberships, #merge_requests, #move!, #notes, #paid?, #pats, #pipeline_variables, #pipelines, #preferences, #projects, readonly_attributes, #reject!, #revoke!, #rotate!, #save!, #ssh_keys, #status, #store_original_attributes, #subscribe!, #support_pin, to_hash, #tokens, #unban!, #unblock!, #unsubscribe!, #webhooks

Constructor Details

This class inherits a constructor from SupportOps::GitLab::Base

Instance Attribute Details

#action_name ⇒ String

Returns the current value of action_name.

Returns:

  • (String) —

    the current value of action_name



27
28
29
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 27

def action_name
  @action_name
end

#author ⇒ Hash

Returns the current value of author.

Returns:

  • (Hash) —

    the current value of author



27
28
29
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 27

def author
  @author
end

#author_id ⇒ Integer

Returns the current value of author_id.

Returns:

  • (Integer) —

    the current value of author_id



27
28
29
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 27

def author_id
  @author_id
end

#author_username ⇒ String

Returns the current value of author_username.

Returns:

  • (String) —

    the current value of author_username



27
28
29
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 27

def author_username
  @author_username
end

#id ⇒ Integer

Returns the current value of id.

Returns:

  • (Integer) —

    the current value of id



27
28
29
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 27

def id
  @id
end

#imported ⇒ Boolean

Returns the current value of imported.

Returns:

  • (Boolean) —

    the current value of imported



27
28
29
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 27

def imported
  @imported
end

#imported_from ⇒ String

Returns the current value of imported_from.

Returns:

  • (String) —

    the current value of imported_from



27
28
29
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 27

def imported_from
  @imported_from
end

#project_id ⇒ Integer

Returns the current value of project_id.

Returns:

  • (Integer) —

    the current value of project_id



27
28
29
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 27

def project_id
  @project_id
end

#target_id ⇒ Integer

Returns the current value of target_id.

Returns:

  • (Integer) —

    the current value of target_id



27
28
29
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 27

def target_id
  @target_id
end

#target_iid ⇒ Integer

Returns the current value of target_iid.

Returns:

  • (Integer) —

    the current value of target_iid



27
28
29
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 27

def target_iid
  @target_iid
end

#target_title ⇒ String

Returns the current value of target_title.

Returns:

  • (String) —

    the current value of target_title



27
28
29
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 27

def target_title
  @target_title
end

#target_type ⇒ String

Returns the current value of target_type.

Returns:

  • (String) —

    the current value of target_type



27
28
29
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 27

def target_type
  @target_type
end

#title ⇒ String

Returns the current value of title.

Returns:

  • (String) —

    the current value of title



27
28
29
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 27

def title
  @title
end

Class Method Details

.list(key: value) ⇒ Array

List all visible events for a project

Examples:

require 'support_ops_gitlab'

SupportOps::GitLab::Configuration.configure do |config|
  config.url = 'https://gitlab.example.com/api/v4'
  config.token = 'abc123'
end

events = SupportOps::GitLab::Events.list(project_id: 123456)
pp events.count
# => 48
pp events.last.action_name
# => "opened"

Parameters:

  • project_id (Integer or String required) —

    The ID or URL-encoded path of the project to get events for

  • action (String optional) —

    If defined, returns events with the specified action type (approved, closed, commented, created, destroyed, expired, joined, left, merge, pushed, reopened, updated)

  • after (String optional) —

    If defined, returns tokens created after the specified date (expects ISO 8601 format)

  • before (String optional) —

    If defined, returns tokens created before the specified date (expects ISO 8601 format)

  • sort (String optional) —

    Direction to sort the results by creation date; possible values: asc, desc

  • target_type (String optional) —

    If defined, returns events with the specified target type (epic, issue, merge_request, milestone, note, project, snippet, user)

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 138

def self.list_project(**args)
  raise 'You have to provide a project_id' if args[:project_id].nil?
  args[:action] = nil unless args[:action]
  args[:after] = nil unless args[:after]
  args[:before] = nil unless args[:before]
  args[:sort] = nil unless args[:sort]
  args[:target_type] = nil unless args[:target_type]
  params = ''
  params += "action=#{args[:action]}&" unless args[:action].nil?
  params += "after=#{args[:after]}&" unless args[:after].nil?
  params += "before=#{args[:before]}&" unless args[:before].nil?
  params += "sort=#{args[:sort]}&" unless args[:sort].nil?
  params += "target_type=#{args[:target_type]}&" unless args[:target_type].nil?
  array = []
  page = 1
  loop do
    response = client.connection.get("projects/#{args[:project_id]}/events?#{params}&page=#{page}&per_page=100")
    body = Oj.load(response.body)
    array += body.map { |e| Events.new(e) }
    break if body.count < 100

    page += 1
  end
  array
end

.list(key: value) ⇒ Array

Get contribution events for a user

Examples:

require 'support_ops_gitlab'

SupportOps::GitLab::Configuration.configure do |config|
  config.url = 'https://gitlab.example.com/api/v4'
  config.token = 'abc123'
end

events = SupportOps::GitLab::Events.list(user_id: 123456)
pp events.count
# => 30
pp events.last.action_name
# => "closed"

Parameters:

  • user_id (Integer or String required) —

    The ID or username of the user to get events for

  • action (String optional) —

    If defined, returns events with the specified action type (approved, closed, commented, created, destroyed, expired, joined, left, merge, pushed, reopened, updated)

  • after (String optional) —

    If defined, returns tokens created after the specified date (expects ISO 8601 format)

  • before (String optional) —

    If defined, returns tokens created before the specified date (expects ISO 8601 format)

  • sort (String optional) —

    Direction to sort the results by creation date; possible values: asc, desc

  • target_type (String optional) —

    If defined, returns events with the specified target type (epic, issue, merge_request, milestone, note, project, snippet, user)

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 74

def self.list_user(**args)
  raise 'You have to provide a user_id' if args[:user_id].nil?
  args[:action] = nil unless args[:action]
  args[:after] = nil unless args[:after]
  args[:before] = nil unless args[:before]
  args[:sort] = nil unless args[:sort]
  args[:target_type] = nil unless args[:target_type]
  params = ''
  params += "action=#{args[:action]}&" unless args[:action].nil?
  params += "after=#{args[:after]}&" unless args[:after].nil?
  params += "before=#{args[:before]}&" unless args[:before].nil?
  params += "sort=#{args[:sort]}&" unless args[:sort].nil?
  params += "target_type=#{args[:target_type]}&" unless args[:target_type].nil?
  array = []
  page = 1
  loop do
    response = client.connection.get("users/#{args[:user_id]}/events?#{params}&page=#{page}&per_page=100")
    body = Oj.load(response.body)
    array += body.map { |e| Events.new(e) }
    break if body.count < 100

    page += 1
  end
  array
end