Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gitlab api v4 #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/puppet/provider/git_deploy_key/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def exists?
project_id = get_project_id

sshkey_hash = Hash.new
url = "#{gms_server}/api/v3/projects/#{project_id}/keys"
url = "#{gms_server}/api/v4/projects/#{project_id}/keys"

response = api_call('GET', url)

Expand All @@ -96,9 +96,9 @@ def get_project_id
raise(Puppet::Error, "gitlab_deploy_key::#{calling_method}: Must provide at least one of the following attributes: project_id or project_name")
end

project_name = resource[:project_name].strip.sub('/','%2F')
project_name = resource[:project_name].strip.gsub('/','%2F')

url = "#{gms_server}/api/v3/projects/#{project_name}"
url = "#{gms_server}/api/v4/projects/#{project_name}"

begin
response = api_call('GET', url)
Expand All @@ -115,7 +115,7 @@ def get_key_id

keys_hash = Hash.new

url = "#{gms_server}/api/v3/projects/#{project_id}/keys"
url = "#{gms_server}/api/v4/projects/#{project_id}/keys"

response = api_call('GET', url)

Expand All @@ -138,7 +138,7 @@ def get_key_id
def create
project_id = get_project_id

url = "#{gms_server}/api/v3/projects/#{project_id}/keys"
url = "#{gms_server}/api/v4/projects/#{project_id}/keys"

begin
response = api_call('POST', url, {'title' => resource[:name].strip, 'key' => File.read(resource[:path].strip)})
Expand All @@ -159,7 +159,7 @@ def destroy
key_id = get_key_id

unless key_id.nil?
url = "#{gms_server}/api/v3/projects/#{project_id}/keys/#{key_id}"
url = "#{gms_server}/api/v4/projects/#{project_id}/keys/#{key_id}"

begin
response = api_call('DELETE', url)
Expand Down
8 changes: 4 additions & 4 deletions lib/puppet/provider/git_groupteam/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def api_call(action,url,data = nil)

def exists?
groupteam_hash = Hash.new
url = "#{gms_server}/api/v3/groups"
url = "#{gms_server}/api/v4/groups"

response = api_call('GET', url)

Expand Down Expand Up @@ -96,7 +96,7 @@ def exists?
def get_group_id
group_hash = Hash.new

url = "#{gms_server}/api/v3/groups"
url = "#{gms_server}/api/v4/groups"

response = api_call('GET', url)

Expand All @@ -117,7 +117,7 @@ def get_group_id
end

def create
url = "#{gms_server}/api/v3/groups"
url = "#{gms_server}/api/v4/groups"

begin
opts = { 'name' => resource[:groupteam_name].strip, 'path' => resource[:groupteam_name].strip }
Expand All @@ -144,7 +144,7 @@ def destroy
group_id = get_group_id

unless group_id.nil?
url = "#{gms_server}/api/v3/groups/#{group_id}"
url = "#{gms_server}/api/v4/groups/#{group_id}"

begin
response = api_call('DELETE', url)
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet/provider/git_groupteam_member/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def exists?
group_id = get_group_id

groupteam_hash = Hash.new
url = "#{gms_server}/api/v3//groups/#{group_id}/members"
url = "#{gms_server}/api/v4//groups/#{group_id}/members"

response = api_call('GET', url)

Expand Down Expand Up @@ -130,7 +130,7 @@ def get_access_level
def get_group_id
group_hash = Hash.new

url = "#{gms_server}/api/v3/groups?search=#{resource[:groupteam_name].strip}"
url = "#{gms_server}/api/v4/groups?search=#{resource[:groupteam_name].strip}"

response = api_call('GET', url)

Expand All @@ -153,7 +153,7 @@ def get_group_id
def get_user_id
group_hash = Hash.new

url = "#{gms_server}/api/v3/users?search=#{resource[:member_name].strip}"
url = "#{gms_server}/api/v4/users?search=#{resource[:member_name].strip}"

response = api_call('GET', url)

Expand All @@ -178,7 +178,7 @@ def create
group_id = get_group_id
user_id = get_user_id

url = "#{gms_server}/api/v3//groups/#{group_id}/members"
url = "#{gms_server}/api/v4//groups/#{group_id}/members"

begin
if access_level.nil? || group_id.nil? || user_id.nil?
Expand Down Expand Up @@ -206,7 +206,7 @@ def destroy
user_id = get_user_id

unless group_id.nil?
url = "#{gms_server}/api/v3//groups/#{group_id}/members/#{user_id}"
url = "#{gms_server}/api/v4//groups/#{group_id}/members/#{user_id}"

begin
response = api_call('DELETE', url)
Expand Down
12 changes: 6 additions & 6 deletions lib/puppet/provider/git_webhook/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def exists?
project_id = get_project_id

webhook_hash = Hash.new
url = "#{gms_server}/api/v3/projects/#{project_id}/hooks"
url = "#{gms_server}/api/v4/projects/#{project_id}/hooks"

response = api_call('GET', url)

Expand Down Expand Up @@ -97,9 +97,9 @@ def get_project_id
raise(Puppet::Error, "gitlab_webhook::#{calling_method}: Must provide at least one of the following attributes: project_id or project_name")
end

project_name = resource[:project_name].strip.sub('/','%2F')
project_name = resource[:project_name].strip.gsub('/','%2F')

url = "#{gms_server}/api/v3/projects/#{project_name}"
url = "#{gms_server}/api/v4/projects/#{project_name}"

begin
response = api_call('GET', url)
Expand All @@ -116,7 +116,7 @@ def get_webhook_id

webhook_hash = Hash.new

url = "#{gms_server}/api/v3/projects/#{project_id}/hooks"
url = "#{gms_server}/api/v4/projects/#{project_id}/hooks"

response = api_call('GET', url)

Expand All @@ -138,7 +138,7 @@ def get_webhook_id
def create
project_id = get_project_id

url = "#{gms_server}/api/v3/projects/#{project_id}/hooks"
url = "#{gms_server}/api/v4/projects/#{project_id}/hooks"

begin
opts = { 'url' => resource[:webhook_url].strip }
Expand Down Expand Up @@ -181,7 +181,7 @@ def destroy
webhook_id = get_webhook_id

unless webhook_id.nil?
url = "#{gms_server}/api/v3/projects/#{project_id}/hooks/#{webhook_id}"
url = "#{gms_server}/api/v4/projects/#{project_id}/hooks/#{webhook_id}"

begin
response = api_call('DELETE', url)
Expand Down
12 changes: 6 additions & 6 deletions lib/puppet/provider/gms_webhook/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.instances

instances = []

repos_url = "#{gms_server}/api/v3/projects"
repos_url = "#{gms_server}/api/v4/projects"
repos = get(repos_url, @token)

webhooks = Array.new
Expand All @@ -37,7 +37,7 @@ def self.instances
repos.each do |r|

# hooks_url = "#{gms_server}/projects/#{r['id']}/hooks"
hooks_url = "#{gms_server}/api/v3/projects/#{r['id']}/hooks"
hooks_url = "#{gms_server}/api/v4/projects/#{r['id']}/hooks"

hook_objs = get(hooks_url, @token)

Expand Down Expand Up @@ -137,7 +137,7 @@ def calling_method

def get_project_id(project_name)
begin
repos_url = "#{self.gms_server}/api/v3/projects"
repos_url = "#{self.gms_server}/api/v4/projects"
repos = PuppetX::Puppetlabs::Gms.get(repos_url, get_token)

repos.each do |r|
Expand All @@ -158,7 +158,7 @@ def exists?
def flush
Puppet.debug("def flush")

put_url = "#{gms_server}/api/v3/projects/#{get_project_id(resource[:project_name].strip)}/hooks/#{self.id}"
put_url = "#{gms_server}/api/v4/projects/#{get_project_id(resource[:project_name].strip)}/hooks/#{self.id}"

if @property_hash != {}
begin
Expand All @@ -179,7 +179,7 @@ def create
Puppet.debug('def create')

begin
post_url = "#{self.gms_server}/api/v3/projects/#{get_project_id(resource[:project_name].strip)}/hooks"
post_url = "#{self.gms_server}/api/v4/projects/#{get_project_id(resource[:project_name].strip)}/hooks"

response = PuppetX::Puppetlabs::Gms.post(post_url, get_token, message(resource))

Expand All @@ -202,7 +202,7 @@ def destroy
Puppet.debug("def destroy")

unless webhook_id.nil?
destroy_url = "#{gms_server}/api/v3/projects/#{get_project_id(resource[:project_name].strip)}/hooks/#{self.id}"
destroy_url = "#{gms_server}/api/v4/projects/#{get_project_id(resource[:project_name].strip)}/hooks/#{self.id}"

begin
response = PuppetX::Puppetlabs::Gms.delete(destroy_url, get_token)
Expand Down