File: repositories.rb

package info (click to toggle)
ruby-gitlab 6.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,824 kB
  • sloc: ruby: 12,742; makefile: 7; sh: 4; javascript: 3
file content (130 lines) | stat: -rw-r--r-- 5,738 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# frozen_string_literal: true

class Gitlab::Client
  # Defines methods related to repositories.
  # @see https://docs.gitlab.com/ce/api/repositories.html
  module Repositories
    # Get file tree project (root level).
    #
    # @example
    #   Gitlab.tree(42)
    #   Gitlab.tree(42, { path: 'Gemfile' })
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [Hash] options A customizable set of options.
    # @option options [String] :path The path inside repository.
    # @option options [String] :ref The name of a repository branch or tag.
    # @option options [Integer] :per_page Number of results to show per page (default = 20)
    # @return [Gitlab::ObjectifiedHash]
    def tree(project, options = {})
      get("/projects/#{url_encode project}/repository/tree", query: options)
    end
    alias repo_tree tree

    # Get project repository archive
    #
    # @example
    #   Gitlab.repo_archive(42)
    #   Gitlab.repo_archive(42, 'deadbeef')
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [String] ref The commit sha, branch, or tag to download.
    # @param  [String] format The archive format. Options are: tar.gz (default), tar.bz2, tbz, tbz2, tb2, bz2, tar, and zip
    # @return [Gitlab::FileResponse]
    def repo_archive(project, ref = 'master', format = 'tar.gz')
      get("/projects/#{url_encode project}/repository/archive.#{format}",
          format: nil,
          headers: { Accept: 'application/octet-stream' },
          query: { sha: ref },
          parser: proc { |body, _|
            if body.encoding == Encoding::ASCII_8BIT # binary response
              ::Gitlab::FileResponse.new StringIO.new(body, 'rb+')
            else # error with json response
              ::Gitlab::Request.parse(body)
            end
          })
    end

    # Compares branches, tags or commits.
    #
    # @example
    #   Gitlab.compare(42, 'master', 'feature/branch')
    #   Gitlab.repo_compare(42, 'master', 'feature/branch')
    #
    # @param [Integer] project The ID of a project.
    # @param [String] from The commit SHA or branch name of from branch.
    # @param [String] to The commit SHA or branch name of to branch.
    # @return [Gitlab::ObjectifiedHash]
    def compare(project, from, to)
      get("/projects/#{url_encode project}/repository/compare", query: { from: from, to: to })
    end
    alias repo_compare compare

    # Get the common ancestor for 2 refs (commit SHAs, branch names or tags).
    #
    # @example
    #   Gitlab.merge_base(42, ['master', 'feature/branch'])
    #   Gitlab.merge_base(42, ['master', 'feature/branch'])
    #
    # @param [Integer, String] project The ID or URL-encoded path of the project.
    # @param [Array] refs Array containing 2 commit SHAs, branch names, or tags.
    # @return [Gitlab::ObjectifiedHash]
    def merge_base(project, refs)
      get("/projects/#{url_encode project}/repository/merge_base", query: { refs: refs })
    end

    # Get project repository contributors.
    #
    # @example
    #   Gitlab.contributors(42)
    #   Gitlab.contributors(42, { order: 'name' })
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [Hash] options A customizable set of options.
    # @option options [String] :order_by Order by name, email or commits (default = commits).
    # @option options [String] :sort Sort order asc or desc (default = asc).
    # @return [Array<Gitlab::ObjectifiedHash>]
    def contributors(project, options = {})
      get("/projects/#{url_encode project}/repository/contributors", query: options)
    end
    alias repo_contributors contributors

    # Generate changelog data
    #
    # @example
    #   Gitlab.generate_changelog(42, 'v1.0.0')
    #   Gitlab.generate_changelog(42, 'v1.0.0', branch: 'main')
    #
    # @param [Integer, String] project The ID or name of a project
    # @param [String] version The version to generate the changelog for
    # @param [Hash] options A customizable set of options
    # @option options [String] :from The start of the range of commits (SHA)
    # @option options [String] :to The end of the range of commits (as a SHA) to use for the changelog
    # @option options [String] :date The date and time of the release, defaults to the current time
    # @option options [String] :branch The branch to commit the changelog changes to
    # @option options [String] :trailer The Git trailer to use for including commits
    # @option options [String] :file The file to commit the changes to
    # @option options [String] :message The commit message to produce when committing the changes
    # @return [bool]
    def generate_changelog(project, version, options = {})
      post("/projects/#{url_encode project}/repository/changelog", body: options.merge(version: version))
    end

    # Get changelog data
    #
    # @example
    #   Gitlab.get_changelog(42, 'v1.0.0')
    #
    # @param [Integer, String] project The ID or name of a project
    # @param [String] version The version to generate the changelog for
    # @param [Hash] options A customizable set of options
    # @option options [String] :from The start of the range of commits (SHA)
    # @option options [String] :to The end of the range of commits (as a SHA) to use for the changelog
    # @option options [String] :date The date and time of the release, defaults to the current time
    # @option options [String] :trailer The Git trailer to use for including commits
    # @return [Gitlab::ObjectifiedHash]
    def get_changelog(project, version, options = {})
      get("/projects/#{url_encode project}/repository/changelog", body: options.merge(version: version))
    end
  end
end