Class: PdkSync::GitPlatformClient

Inherits:
Object
  • Object
show all
Defined in:
lib/pdksync/gitplatformclient.rb

Instance Method Summary collapse

Constructor Details

#initialize(git_platform, git_platform_access_settings) ⇒ GitPlatformClient

Returns a new instance of GitPlatformClient.

Parameters:

  • git_platform (Symbol)

    The symbol designating the Git hosting platform to use and thus which client to create

  • git_platform_access_settings (Hash)

    Hash of Git platform access settings, such as access_token or gitlab_api_endpoint. access_token is always required, gitlab_api_endpoint only for Gitlab.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pdksync/gitplatformclient.rb', line 18

def initialize(git_platform, git_platform_access_settings)
  @git_platform = git_platform

  # TODO: raise exceptions when git_platform_access_settings hash is not
  # set up correctly? Or let PdkSync::GithubClient or PdkSync::GitlabClient
  # raise errors later and let them propagate upwards?
  access_token = git_platform_access_settings[:access_token]
  @client = case git_platform
            when :github
              require 'pdksync/githubclient'

              PdkSync::GithubClient.new(access_token, git_platform_access_settings[:api_endpoint])
            when :gitlab
              require 'pdksync/gitlabclient'

              gitlab_api_endpoint = git_platform_access_settings[:gitlab_api_endpoint] || git_platform_access_settings[:api_endpoint]
              PdkSync::GitlabClient.new(access_token, gitlab_api_endpoint)
            end
end

Instance Method Details

#create_pull_request(project, target_branch, source_branch, title, message) ⇒ PdkSync::PullRequest

Returns A pdksync pull request object for the newly created pull/merge request for consumption by pdksync main.

Parameters:

  • project (String)

    The full project name, i.e. “namespace/project” in which to create the pull/merge request

  • target_branch (String)

    The target branch against which to create the pull/merge request

  • source_branch (String)

    The source branch from which to create the pull/merge request

  • title (String)

    The title/name of the pull/merge request to create

  • message (String)

    The pull/merge request message/body

Returns:

  • (PdkSync::PullRequest)

    A pdksync pull request object for the newly created pull/merge request for consumption by pdksync main



64
65
66
67
68
69
70
71
72
73
# File 'lib/pdksync/gitplatformclient.rb', line 64

def create_pull_request(project, target_branch, source_branch, title, message)
  client_pr = @client.create_pull_request(project, target_branch, source_branch, title, message)
  pr = case @git_platform
       when :github
         PdkSync::PullRequest.github(client_pr)
       when :gitlab
         PdkSync::PullRequest.gitlab(client_pr)
       end
  pr
end

#delete_branch(project, branch_name) ⇒ Boolean

Returns true on success, false on failure.

Parameters:

  • project (String)

    The full project name, i.e. “namespace/project” in which to delete the branch

  • branch_name (String)

    The name of the branch to delete

Returns:

  • (Boolean)

    true on success, false on failure



106
107
108
# File 'lib/pdksync/gitplatformclient.rb', line 106

def delete_branch(project, branch_name)
  @client.delete_branch(project, branch_name)
end

#labels(project) ⇒ Array

Returns List of available labels in the project.

Parameters:

  • project (String)

    The full project name, i.e. “namespace/project”, from which to get the available labels

Returns:

  • (Array)

    List of available labels in the project



80
81
82
# File 'lib/pdksync/gitplatformclient.rb', line 80

def labels(project)
  @client.labels(project)
end

#repository?(project) ⇒ Boolean

Returns true if the project exists, false otherwise.

Parameters:

  • project (String)

    The full repository name, i.e. “namespace/project”

Returns:

  • (Boolean)

    true if the project exists, false otherwise



42
43
44
# File 'lib/pdksync/gitplatformclient.rb', line 42

def repository?(project)
  @client.repository?(project)
end

#update_issue(project, id, options) ⇒ Object

Note:

This method is specifically used to set labels for a pull/merge request

Returns A pull/merge request object of the updated pull/merge request.

Parameters:

  • project (String)

    The full project name, i.e. “namespace/project” in which to update the issue

  • id (Integer)

    The id number of the pull/merge request to update

  • options (Hash)

    A hash of options defining the changes to the pull/merge request

Returns:

  • A pull/merge request object of the updated pull/merge request



95
96
97
# File 'lib/pdksync/gitplatformclient.rb', line 95

def update_issue(project, id, options)
  @client.update_issue(project, id, options)
end