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

Merge develop into cleanup #215

Merged
merged 14 commits into from
Feb 24, 2021
Merged
54 changes: 28 additions & 26 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-02-08 20:16:39 +0100 using RuboCop version 0.75.0.
# on 2021-02-18 21:56:11 +0100 using RuboCop version 0.75.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.


# Offense count: 32
Lint/IneffectiveAccessModifier:
Exclude:
Expand Down Expand Up @@ -40,7 +39,7 @@ Lint/UselessAccessModifier:
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb'

# Offense count: 8
# Offense count: 6
Lint/UselessAssignment:
Exclude:
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_validate_lib_strings_action.rb'
Expand All @@ -57,7 +56,7 @@ Naming/AccessorMethodName:
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb'
- 'spec/spec_helper.rb'

# Offense count: 88
# Offense count: 89
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros.
# NamePrefix: is_, has_, have_
# NamePrefixBlacklist: is_, has_, have_
Expand All @@ -78,7 +77,7 @@ Naming/UncommunicativeMethodParamName:
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_update_helper.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/promo_screenshots_helper.rb'

# Offense count: 80
# Offense count: 78
# Configuration parameters: EnforcedStyle.
# SupportedStyles: snake_case, camelCase
Naming/VariableName:
Expand All @@ -100,39 +99,43 @@ Naming/VariableNumber:
Exclude:
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/configure_helper.rb'

# Offense count: 3
# Offense count: 5
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/ci_helper_spec.rb'
- 'spec/git_helper_spec.rb'
- 'spec/ios_lint_localizations_spec.rb'

# Offense count: 21
# Offense count: 25
# Cop supports --auto-correct.
# Configuration parameters: SkipBlocks, EnforcedStyle.
# SupportedStyles: described_class, explicit
RSpec/DescribedClass:
Exclude:
- 'spec/ci_helper_spec.rb'
- 'spec/configuration_spec.rb'
- 'spec/encryption_helper_spec.rb'
- 'spec/file_reference_spec.rb'
- 'spec/git_helper_spec.rb'
- 'spec/ios_lint_localizations_spec.rb'

# Offense count: 4
# Offense count: 5
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/ci_helper_spec.rb'
- 'spec/configuration_spec.rb'
- 'spec/ios_lint_localizations_spec.rb'
- 'spec/release_notes_helper_spec.rb'

# Offense count: 8
# Offense count: 9
# Configuration parameters: CustomTransform, IgnoreMethods, SpecSuffixOnly.
RSpec/FilePath:
Exclude:
- 'spec/android_merge_translators_strings_spec.rb'
- 'spec/ci_helper_spec.rb'
- 'spec/configuration_spec.rb'
- 'spec/encryption_helper_spec.rb'
- 'spec/file_reference_spec.rb'
Expand Down Expand Up @@ -186,10 +189,11 @@ RSpec/MessageSpies:
RSpec/MultipleExpectations:
Max: 7

# Offense count: 34
# Offense count: 35
# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Exclude:
- 'spec/ci_helper_spec.rb'
- 'spec/configuration_spec.rb'
- 'spec/file_reference_spec.rb'

Expand Down Expand Up @@ -228,7 +232,7 @@ Style/AsciiComments:
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/promo_screenshots_helper.rb'
- 'spec/ios_lint_localizations_spec.rb'

# Offense count: 91
# Offense count: 95
Style/Documentation:
Enabled: false

Expand All @@ -238,21 +242,17 @@ Style/GlobalVars:
Exclude:
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/promo_screenshots_helper.rb'

# Offense count: 21
# Offense count: 10
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_localize_libs_action.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/extract_release_notes_for_version_action.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_download_action.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_validate_action.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_update_metadata_source.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/an_metadata_update_helper.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/configure_helper.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/git_helper.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_update_helper.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/promo_screenshots_helper.rb'

# Offense count: 2
Expand Down Expand Up @@ -349,12 +349,20 @@ Style/RedundantBegin:
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/get_prs_list_action.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/promo_screenshots_helper.rb'

# Offense count: 65
# Offense count: 16
# Cop supports --auto-correct.
Style/RedundantParentheses:
Enabled: false
Exclude:
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_new_milestone_action.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/extract_release_notes_for_version_action.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/add_development_certificates_to_provisioning_profiles.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/add_devices_to_provisioning_profiles.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_update_metadata_source.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_download_helper.rb'

# Offense count: 40
# Offense count: 39
# Cop supports --auto-correct.
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
Expand All @@ -375,7 +383,7 @@ Style/RedundantSelf:
- 'spec/android_merge_translators_strings_spec.rb'
- 'spec/ios_merge_translators_strings_spec.rb'

# Offense count: 7
# Offense count: 6
# Cop supports --auto-correct.
Style/RescueModifier:
Exclude:
Expand Down Expand Up @@ -480,12 +488,6 @@ Style/UnneededInterpolation:
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_download_action.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_translators_strings.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/UnneededPercentQ:
Exclude:
- 'Dangerfile'

# Offense count: 4
# Cop supports --auto-correct.
Style/ZeroLengthPredicate:
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
source('https://rubygems.org')

gemspec

gem 'danger', '~> 8.0'

group :test do
gem 'codecov', require: false
gem 'rspec'
gem 'webmock', require: false, group: :test
gem 'yard'
end

Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ GEM
concurrent-ruby (1.1.8)
cork (0.3.0)
colored2 (~> 3.1)
crack (0.4.5)
rexml
danger (8.2.1)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
Expand Down Expand Up @@ -166,6 +168,7 @@ GEM
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (~> 0.14)
hashdiff (1.0.1)
highline (1.7.10)
http-cookie (1.0.3)
domain_name (~> 0.5)
Expand Down Expand Up @@ -293,6 +296,10 @@ GEM
unf_ext
unf_ext (0.0.7.7)
unicode-display_width (1.6.1)
webmock (3.11.1)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
word_wrap (1.0.0)
xcodeproj (1.19.0)
CFPropertyList (>= 2.3.3, < 4.0)
Expand Down Expand Up @@ -323,6 +330,7 @@ DEPENDENCIES
rubocop-require_tools (~> 0.1.2)
rubocop-rspec
simplecov (~> 0.16.1)
webmock
yard

BUNDLED WITH
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module Fastlane
module Actions
class CircleciTriggerJobAction < Action
def self.run(params)
require_relative '../../helper/ci_helper.rb'

UI.message "Triggering job #{params[:job_params]} on branch #{params[:branch]}"

ci_helper = Fastlane::Helper::CircleCIHelper.new(
login: params[:circle_ci_token],
repository: params[:repository],
organization: params[:organization]
)

res = ci_helper.trigger_job(branch: params[:branch], parameters: params[:job_params])
res.code == '201' ? UI.message('Done!') : UI.user_error!("Failed to start job\nError: [#{res.code}] #{res.message}")
end

#####################################################
# @!group Documentation
#####################################################

def self.description
'Triggers a job on CircleCI'
end

def self.available_options
[
FastlaneCore::ConfigItem.new(key: :circle_ci_token,
env_name: 'FL_CIRCLECI_TOKEN',
description: 'CircleCI token',
type: String),
FastlaneCore::ConfigItem.new(key: :organization,
env_name: 'FL_CIRCLECI_ORGANIZATION',
description: 'The GitHub organization which hosts the repository you want to work on',
type: String,
default_value: 'wordpress-mobile'),
FastlaneCore::ConfigItem.new(key: :repository,
env_name: 'FL_CIRCLECI_REPOSITORY',
description: 'The GitHub repository you want to work on',
type: String),
FastlaneCore::ConfigItem.new(key: :branch,
env_name: 'FL_CIRCLECI_BRANCH',
description: 'The branch on which you want to work on',
type: String),
FastlaneCore::ConfigItem.new(key: :job_params,
env_name: 'FL_CIRCLECI_JOB_PARAMS',
description: 'Parameters to send to the CircleCI pipeline',
type: Hash,
default_value: nil)
]
end

def self.authors
['loremattei']
end
end
end
end
91 changes: 91 additions & 0 deletions lib/fastlane/plugin/wpmreleasetoolkit/helper/ci_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
require 'fastlane_core/ui/ui'
require 'net/http'
require 'uri'
require 'json'

module CIHelper
# Triggers a job on CI
#
# @param [String] The branch on which the job should run
# @param [Parameters] CI provider specific parameters
#
def trigger_job(branch:, parameters: nil)
raise 'Not implemented'
end

# Login
#
# @return [String] The CI login credentials
#
def login
raise 'Not implemented'
end

# Organization
#
# @return [String] The organization the repository belongs to
#
def organization
raise 'Not implemented'
end

# Repository
#
# @return [String] The repository name
#
def repository
raise 'Not implemented'
end
end

module Fastlane
module Helper
class CircleCIHelper
include CIHelper

attr_accessor :login, :organization, :repository

# Initializes CircleCI helper.
#
# @param [String] login The CI login credentials. Usually a personal token on CircleCI
# @param [String] repository The repository name
# @param [String] organization The organization the repository belongs to
#
def initialize(login:, repository:, organization: 'wordpress-mobile')
@login = login
@organization = organization
@repository = repository
end

# Command URI
#
# @return [String] The CI API URI
#
def command_uri
URI.parse("https://circleci.com/api/v2/project/github/#{@organization}/#{@repository}/pipeline")
end

# Triggers a job on CI
#
# @param [String] The branch on which the job should run
# @param [Parameters] CI provider specific parameters
# @return [Net::HTTPResponse] The HTTP response
#
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
end
end
end
Loading