Class: Fastlane::Helper::CircleCIHelper

Inherits:
Object
  • Object
show all
Includes:
CIHelper
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/helper/ci_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(login:, repository:, organization: 'wordpress-mobile') ⇒ CircleCIHelper

Initializes CircleCI helper.

Parameters:

  • login (String)

    The CI login credentials. Usually a personal token on CircleCI

  • repository (String)

    The repository name

  • organization (String) (defaults to: 'wordpress-mobile')

    The organization the repository belongs to



54
55
56
57
58
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ci_helper.rb', line 54

def initialize(login:, repository:, organization: 'wordpress-mobile')
  @login = 
  @organization = organization
  @repository = repository
end

Instance Attribute Details

#loginObject

Returns the value of attribute login.



46
47
48
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ci_helper.rb', line 46

def 
  @login
end

#organizationObject

Returns the value of attribute organization.



46
47
48
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ci_helper.rb', line 46

def organization
  @organization
end

#repositoryObject

Returns the value of attribute repository.



46
47
48
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ci_helper.rb', line 46

def repository
  @repository
end

Instance Method Details

#command_uriString

Command URI

Returns:

  • (String)

    The CI API URI



64
65
66
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ci_helper.rb', line 64

def command_uri
  URI.parse("https://circleci.com/api/v2/project/github/#{@organization}/#{@repository}/pipeline")
end

#trigger_job(branch:, parameters: nil) ⇒ Net::HTTPResponse

Triggers a job on CI

Parameters:

  • branch (String)

    The branch on which the job should run

  • parameters (Hash) (defaults to: nil)

    CI provider specific parameters

Returns:

  • (Net::HTTPResponse)

    The HTTP response



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ci_helper.rb', line 74

def trigger_job(branch:, parameters: nil)
  headers = {
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'Circle-Token' => @login
  }

  Net::HTTP.start(command_uri.host, command_uri.port, use_ssl: true) do |http|
    request = Net::HTTP::Post.new(command_uri.request_uri, headers)
    body = { branch: branch, parameters: parameters }
    request.body = body.to_json
    response = http.request(request)
    return response
  end
end