Class: UniversalGitClient::Http::BitbucketServer

Inherits:
Base
  • Object
show all
Defined in:
lib/universal-git-client/http/bitbucket_server.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from ResponseValidation

#with_response_validation!

Constructor Details

This class inherits a constructor from UniversalGitClient::Http::Base

Instance Method Details

#branch(owner:, repo:, branch:) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/universal-git-client/http/bitbucket_server.rb', line 78

def branch(owner:, repo:, branch:)
  with_response_validation! do
    response = self.class.get(
      "/projects/#{owner}/repos/#{repo}/branches",
      default_options.merge(
        query: {
          filterText: branch,
          limit: 1
        }
      )
    )
    Helpers::DummyResponse.response(request: response.request, body: response.parsed_response['values'].first)
  end
end

#branches(owner:, repo:, page: 1, per_page: nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/universal-git-client/http/bitbucket_server.rb', line 64

def branches(owner:, repo:, page: 1, per_page: nil)
  with_response_validation! do
    self.class.get(
      "/projects/#{owner}/repos/#{repo}/branches",
      default_options.merge(
        query: {
          start: limit(per_page) * (page - 1),
          limit: limit(per_page)
        }
      )
    )
  end
end

#delete_repo_webhook(owner:, repo:, webhook_id:) ⇒ Object



118
119
120
121
122
123
124
125
# File 'lib/universal-git-client/http/bitbucket_server.rb', line 118

def delete_repo_webhook(owner:, repo:, webhook_id:)
  with_response_validation! do
    self.class.delete(
      "/projects/#{owner}/repos/#{repo}/webhooks/#{webhook_id}",
      default_options
    )
  end
end

#download_repo_archive(owner:, repo:, branch: nil) ⇒ Object



93
94
95
# File 'lib/universal-git-client/http/bitbucket_server.rb', line 93

def download_repo_archive(owner:, repo:, branch: nil)
  Down.download("#{base_url}/projects/#{owner}/repos/#{repo}/archive?at=#{branch}&format=zip", down_default_options)
end

#orga_repos(organization:, page: 1, per_page: nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/universal-git-client/http/bitbucket_server.rb', line 42

def orga_repos(organization:, page: 1, per_page: nil)
  options =  default_options.merge(
    query: {
      start: limit(per_page) * (page - 1),
      limit: limit(per_page)
    }
  )
  body = {
    size: 0,
    start: 0,
    limit: limit(per_page),
    values: []
  }
  Helpers::DummyResponse.response(body: body, options: options)
end

#organizations(page: 1, per_page: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/universal-git-client/http/bitbucket_server.rb', line 11

def organizations(page: 1, per_page: nil)
  options = default_options.merge(
    query: {
      start: limit(per_page) * (page - 1),
      limit: limit(per_page)
    }
  )
  body = {
    size: 0,
    start: 0,
    limit: limit(per_page),
    values: []
  }
  Helpers::DummyResponse.response(body: body, options: options)
end

#repository(owner:, repo:) ⇒ Object



58
59
60
61
62
# File 'lib/universal-git-client/http/bitbucket_server.rb', line 58

def repository(owner:, repo:)
  with_response_validation! do
    self.class.get("/projects/#{owner}/repos/#{repo}", default_options)
  end
end

#setup_repo_webhook(owner:, repo:, webhook_url:, webhook_secret: nil) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/universal-git-client/http/bitbucket_server.rb', line 97

def setup_repo_webhook(owner:, repo:, webhook_url:, webhook_secret: nil)
  with_response_validation! do
    self.class.post(
      "/projects/#{owner}/repos/#{repo}/webhooks",
      default_options.merge(
        body: {
          name: 'webhook',
          url: webhook_url,
          active: true,
          events: [
            'repo:refs_changed'
          ],
          configuration: {
            secret: webhook_secret
          }
        }.to_json
      )
    )
  end
end

#userObject



7
8
9
# File 'lib/universal-git-client/http/bitbucket_server.rb', line 7

def user
  Helpers::DummyResponse.response(options: default_options)
end

#user_repos(page: 1, per_page: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/universal-git-client/http/bitbucket_server.rb', line 27

def user_repos(page: 1, per_page: nil)
  with_response_validation! do
    self.class.get(
      '/repos',
      default_options.merge(
        query: {
          state: 'AVAILABLE',
          start: limit(per_page) * (page - 1),
          limit: limit(per_page)
        }
      )
    )
  end
end