Class: SupportOps::GitLab::Commits

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

Overview

TODO:

Document attributes

TODO:

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

Author:

  • Jason Colyer

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance 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!, #diffs, #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!, #ssh_keys, #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

#actionsArray

An array of action hashes to commit as a batch; see API documentation on gitlab for more information (create only)

Returns:

  • (Array)

    the current value of actions



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def actions
  @actions
end

#author_emailString

Returns the current value of author_email.

Returns:

  • (String)

    the current value of author_email



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def author_email
  @author_email
end

#author_nameString

Returns the current value of author_name.

Returns:

  • (String)

    the current value of author_name



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def author_name
  @author_name
end

#authored_dateString

Returns the current value of authored_date.

Returns:

  • (String)

    the current value of authored_date



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def authored_date
  @authored_date
end

#commit_messageString

Returns the current value of commit_message.

Returns:

  • (String)

    the current value of commit_message



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def commit_message
  @commit_message
end

#committed_dateString

Returns the current value of committed_date.

Returns:

  • (String)

    the current value of committed_date



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def committed_date
  @committed_date
end

#committer_emailString

Returns the current value of committer_email.

Returns:

  • (String)

    the current value of committer_email



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def committer_email
  @committer_email
end

#committer_nameString

Returns the current value of committer_name.

Returns:

  • (String)

    the current value of committer_name



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def committer_name
  @committer_name
end

#created_atString

Returns the current value of created_at.

Returns:

  • (String)

    the current value of created_at



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def created_at
  @created_at
end

#extended_trailersHash

Returns the current value of extended_trailers.

Returns:

  • (Hash)

    the current value of extended_trailers



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def extended_trailers
  @extended_trailers
end

#forceBoolean

Returns the current value of force.

Returns:

  • (Boolean)

    the current value of force



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def force
  @force
end

#idString

Returns the current value of id.

Returns:

  • (String)

    the current value of id



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def id
  @id
end

#last_pipelineHash

Returns the current value of last_pipeline.

Returns:

  • (Hash)

    the current value of last_pipeline



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def last_pipeline
  @last_pipeline
end

#messageString

Returns the current value of message.

Returns:

  • (String)

    the current value of message



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def message
  @message
end

#parent_idsArray

Returns the current value of parent_ids.

Returns:

  • (Array)

    the current value of parent_ids



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def parent_ids
  @parent_ids
end

#project_idInteger

Returns the current value of project_id.

Returns:

  • (Integer)

    the current value of project_id



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def project_id
  @project_id
end

#short_idString

Returns the current value of short_id.

Returns:

  • (String)

    the current value of short_id



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def short_id
  @short_id
end

#start_branchString

Returns the current value of start_branch.

Returns:

  • (String)

    the current value of start_branch



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def start_branch
  @start_branch
end

#start_projectInteger

Returns the current value of start_project.

Returns:

  • (Integer)

    the current value of start_project



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def start_project
  @start_project
end

#start_shaString

Returns the current value of start_sha.

Returns:

  • (String)

    the current value of start_sha



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def start_sha
  @start_sha
end

#statsHash

Returns the current value of stats.

Returns:

  • (Hash)

    the current value of stats



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def stats
  @stats
end

#statusString

Returns the current value of status.

Returns:

  • (String)

    the current value of status



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def status
  @status
end

#titleString

Returns the current value of title.

Returns:

  • (String)

    the current value of title



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def title
  @title
end

#trailersBoolean

Git trailers for a commit

Returns:

  • (Boolean)

    the current value of trailers



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def trailers
  @trailers
end

#web_urlString

Returns the current value of web_url.

Returns:

  • (String)

    the current value of web_url



39
40
41
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 39

def web_url
  @web_url
end

Class Method Details

.list(key: value) ⇒ Array

List repository commits

Examples:

require 'support_ops_gitlab'

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

commits = SupportOps::GitLab::Commits.list(project_id: 123)
pp commits.count
# => 115
pp commits.last.title
# => "Aweomse commit"

Parameters:

  • project_id (Integer required)

    The project ID to look in

  • all (Boolean optional)

    Retrieve every commit from the repository; when set to true, the ref_name parameter is ignored

  • author (String optional)

    Search commits by commit author

  • first_parent (Boolean optional)

    Follow only the first parent commit upon seeing a merge commit

  • order (String optional)

    List commits in order; possible values: default, topo; defaults to default, the commits are shown in reverse chronological order

  • path (String optional)

    The file path

  • ref_name (String optional)

    The name of a repository branch, tag or revision range, or if not given the default branch

  • since (String optional)

    Only commits after or on this date are returned in ISO 8601 format YYYY-MM-DDTHH:MM:SSZ

  • until (String optional)

    Only commits before or on this date are returned in ISO 8601 format YYYY-MM-DDTHH:MM:SSZ

  • limit (Integer optional)

    The limit to the number of users returned. Default to 0 (i.e. no limit)

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



129
130
131
132
133
134
135
136
137
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
163
164
165
166
167
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 129

def self.list(**args)
  args[:project_id] = nil unless args[:project_id]
  raise 'You have to provide a project_id' if args[:project_id].nil?
  args[:all] = nil unless args[:all]
  args[:author] = nil unless args[:author]
  args[:first_parent] = nil unless args[:first_parent]
  args[:order] = nil unless args[:order]
  args[:path] = nil unless args[:path]
  args[:ref_name] = nil unless args[:ref_name]
  args[:since] = nil unless args[:since]
  args[:until] = nil unless args[:until]
  args[:limit] = 0 unless args[:limit]
  params = 'with_stats=true&trailers=true&'
  params += "all=#{args[:all]}&" unless args[:all].nil?
  params += "author=#{args[:author]}&" unless args[:author].nil?
  params += "first_parent=#{args[:first_parent]}&" unless args[:first_parent].nil?
  params += "order=#{args[:order]}&" unless args[:order].nil?
  params += "path=#{args[:path]}&" unless args[:path].nil?
  params += "ref_name=#{args[:ref_name]}&" unless args[:ref_name].nil?
  params += "since=#{args[:since]}&" unless args[:since].nil?
  params += "until=#{args[:until]}&" unless args[:until].nil?
  array = []
  page = 1
  loop do
    response = client.connection.get("projects/#{args[:project_id]}/repository/commits?#{params}&page=#{page}&per_page=100")
    body = Oj.load(response.body)
    array += body.map do |c|
      c['project_id'] = args[:project_id]
      Commits.new(c)
    end
    break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
    break if body.count < 100

    page += 1
  end
  return array if args[:limit].to_i.zero?
  
  array.first(args[:limit].to_i)
end

Instance Method Details

#save!Object

Note:

This is inherited from Base#save!

Creates a commit

Examples:

require 'support_ops_gitlab'

SupportOps::GitLab::Configuration.configure do |config|
  config.token = ENV.fetch('GL_TOKEN')
  config.url = 'https://gitlab.com/api/v4'
end

new_commit = SupportOps::GitLab::Commits.new
new_commit.branch = 'master'
new_commit.commit_message = 'Changing some stuff'
new_commit.project_id = 123456
new_commit.actions = [
  { action: 'create', file_path: 'foo/bar', content: 'some content' },
  { action: 'update', file_path: 'foo/bar5', content: 'new content' },
  { action: 'delete', file_path': 'foo/bar2' },
  { action: 'move', file_path: 'foo/bar3', previous_path: 'foo/bar4', content: 'some content' },
  { action: 'chmod', file_path: 'foo/bar5', execute_filemode: true }
]

new_commit.save!

pp new_commit.id
# => "ed899a2f4b50b4370feeea94676502b42383c746"

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



34
# File 'lib/support_ops_gitlab/gitlab/commits.rb', line 34

def save!; end