rake_github 0.12.0.pre.5 → 0.12.0.pre.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eefb4078b238e62e43d8981006e9ef4f2c8828907ccb818298d1bc105e024e10
4
- data.tar.gz: ce8500f07372641a5b2b4b97c16c1f4345ccf733261885888f65fc8ab473bfc5
3
+ metadata.gz: 3548c4b3c703df23155ad789772f96387712de3d2682e5834d0f6def8b928610
4
+ data.tar.gz: 3040b762a2ab6dc3195c3434c1039c072c61643ef749acfca49ceafc405fef40
5
5
  SHA512:
6
- metadata.gz: d93931749dc0d299a79a735d49e56f83acb0d94e672ad1a610ae6f7ac6c0f8ae440c2f7d64ea55cfc7b65a7d71fe3f19a861b1881edd85ce9e0c88d7245cc561
7
- data.tar.gz: 6c793a70446a397c602a2c39f85bb580dc378f478fb1749889bd85b482789bd4809cdd3f91c0e2889fda4d16660ba6e0e24a82ee2b3707691425dbce04f9bc81
6
+ metadata.gz: 97e1be376618e4df2b8a7a2e056d0eea6de7f386cb6852fba9d146464a972f20c2c99cf9123cf57a87e04080288b63288b6a76b6ff186d0d1b689dbaf7eafcbc
7
+ data.tar.gz: 65c2e337dc6d0bfddc0c4870486f8841fababc77e46ca699493a35962dd8d06fe1090249fc0e1a099aab585f899674cf604c93c2f6dd55dcac537ba520f16eea
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rake_github (0.12.0.pre.5)
4
+ rake_github (0.12.0.pre.6)
5
5
  colored2 (~> 3.1)
6
- octokit (>= 4.16, < 8.0)
6
+ octokit (>= 4.16, < 9.0)
7
7
  rake_factory (~> 0.23)
8
8
  sshkey (~> 2.0)
9
9
 
@@ -55,7 +55,7 @@ GEM
55
55
  memfs (1.0.0)
56
56
  minitest (5.20.0)
57
57
  mutex_m (0.1.2)
58
- octokit (7.2.0)
58
+ octokit (8.0.0)
59
59
  faraday (>= 1, < 3)
60
60
  sawyer (~> 0.9)
61
61
  open4 (1.3.4)
data/README.md CHANGED
@@ -32,7 +32,7 @@ require 'rake_github'
32
32
  RakeGithub.define_repository_tasks(
33
33
  namespace: :github,
34
34
  repository: 'org/repo', # required
35
- ) do |t, args|
35
+ ) do |t|
36
36
  t.access_token = "your_github_access_token" # required
37
37
  t.deploy_keys = [
38
38
  {
@@ -40,25 +40,22 @@ RakeGithub.define_repository_tasks(
40
40
  public_key: File.read('path/to/your_deploy_key.public')
41
41
  }
42
42
  ]
43
- t.branch_name = args.branch_name
44
- t.commit_message = args.commit_message
45
43
  end
46
44
  ```
47
45
 
48
46
  | Parameter | Type | Required | Description | Example | Default |
49
47
  |---------------------------------|--------|----------|------------------------------------------------------------|--------------------------------------------------------|--------------------------------------|
50
- | repository | string | Y | Repository to perform tasks upon | 'organisation/repository_name' | N/A |
51
- | access_token | string | Y | Github token for authorisation | 'ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | N/A |
52
- | deploy_keys | array | N | Keys to deploy to repository | { title: string, public_key: string, read_only: bool } | [ ] |
53
- | deploy_keys_namespace | symbol | N | Namespace to contain deploy keys tasks | :deploy_tasks | :deploy_keys |
54
- | deploy_keys_destroy_task_name | symbol | N | Option to change the destroy task name | :obliterate | :destroy |
55
- | deploy_keys_provision_task_name | symbol | N | Option to change the provision task name | :add | :provision |
56
- | deploy_keys_ensure_task_name | symbol | N | Option to change the ensure task name | :destroy_and_provision | :ensure |
57
- | namespace | symbol | N | Namespace for tasks to live in, defaults to root namespace | :rake_github | N/A |
58
- | branch_name | string | N | Branch that can be merged | 'cool_new_feature' | N/A |
59
- | commit_message | string | N | Merge commit message | 'merged PR using Rake Github' | "" (retains original commit message) |
48
+ | repository | string | Y | Repository to perform tasks upon | 'organisation/repository_name' | N/A |
49
+ | access_token | string | Y | Github token for authorisation | 'ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | N/A |
50
+ | deploy_keys | array | N | Keys to deploy to repository | { title: string, public_key: string, read_only: bool } | [ ] |
51
+ | deploy_keys_namespace | symbol | N | Namespace to contain deploy keys tasks | :deploy_tasks | :deploy_keys |
52
+ | deploy_keys_destroy_task_name | symbol | N | Option to change the destroy task name | :obliterate | :destroy |
53
+ | deploy_keys_provision_task_name | symbol | N | Option to change the provision task name | :add | :provision |
54
+ | deploy_keys_ensure_task_name | symbol | N | Option to change the ensure task name | :destroy_and_provision | :ensure |
55
+ | namespace | symbol | N | Namespace for tasks to live in, defaults to root namespace | :rake_github | N/A |
60
56
 
61
57
  Exposes tasks:
58
+
62
59
  ```shell
63
60
  $ rake -T
64
61
 
@@ -69,18 +66,23 @@ rake github:pull_requests:merge[branch_name,commit_message]
69
66
  ```
70
67
 
71
68
  #### deploy_keys:provision
69
+
72
70
  Provisions deploy keys to the specified repository.
73
71
 
74
72
  #### deploy_keys:destroy
73
+
75
74
  Destroys deploy keys from the specified repository.
76
75
 
77
76
  #### deploy_keys:ensure
77
+
78
78
  Destroys and then provisions deploy keys on the specified repository.
79
79
 
80
80
  #### pull_requests:merge[branch_name,commit_message]
81
+
81
82
  Merges the PR associated with the `branch_name`. Branch name is required.
82
83
 
83
- `commit_message` is optional, and can contain the original commit message with the `%s` placeholder, e.g. `pull_requests:merge[new_feature,"%s [skip ci]"]`.
84
+ `commit_message` is optional, and can contain the original commit message with
85
+ the `%s` placeholder, e.g. `pull_requests:merge[new_feature,"%s [skip ci]"]`.
84
86
 
85
87
  ### define_release_task
86
88
 
@@ -121,13 +123,12 @@ openssl aes-256-cbc \
121
123
 
122
124
  ## Contributing
123
125
 
124
- Bug reports and pull requests are welcome on GitHub at
125
- https://github.com/infrablocks/rake_github. This project is intended to be a
126
- safe, welcoming space for collaboration, and contributors are expected to
127
- adhere to the [Contributor Covenant](http://contributor-covenant.org) code of
128
- conduct.
126
+ Bug reports and pull requests are welcome on GitHub at
127
+ https://github.com/infrablocks/rake_github. This project is intended to be a
128
+ safe, welcoming space for collaboration, and contributors are expected to adhere
129
+ to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
129
130
 
130
131
  ## License
131
132
 
132
- The gem is available as open source under the terms of the
133
+ The gem is available as open source under the terms of the
133
134
  [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -146,7 +146,7 @@ end
146
146
  RakeGithub.define_repository_tasks(
147
147
  namespace: :github,
148
148
  repository: 'infrablocks/rake_github'
149
- ) do |t, args|
149
+ ) do |t|
150
150
  github_config =
151
151
  YAML.load_file('config/secrets/github/config.yaml')
152
152
 
@@ -157,8 +157,6 @@ RakeGithub.define_repository_tasks(
157
157
  public_key: File.read('config/secrets/ci/ssh.public')
158
158
  }
159
159
  ]
160
- t.branch_name = args.branch_name
161
- t.commit_message = args.commit_message
162
160
  end
163
161
 
164
162
  namespace :pipeline do
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RakeGithub
4
+ module Exceptions
5
+ class NoPullRequest < StandardError
6
+ attr_reader :branch_name
7
+
8
+ def initialize(branch_name)
9
+ @branch_name = branch_name
10
+
11
+ super(format('No pull request associated with branch %s', branch_name))
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RakeGithub
4
+ module Exceptions
5
+ class RequiredArgumentUnset < ::StandardError
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'exceptions/no_pull_request'
4
+ require_relative 'exceptions/required_argument_unset'
@@ -17,8 +17,6 @@ module RakeGithub
17
17
  parameter :deploy_keys_destroy_task_name, default: :destroy
18
18
  parameter :deploy_keys_provision_task_name, default: :provision
19
19
  parameter :deploy_keys_ensure_task_name, default: :ensure
20
- parameter :branch_name
21
- parameter :commit_message, default: ''
22
20
 
23
21
  task Tasks::DeployKeys::Provision,
24
22
  name: RakeFactory::DynamicValue.new { |ts|
@@ -38,14 +36,7 @@ module RakeGithub
38
36
  destroy_task_name: RakeFactory::DynamicValue.new { |ts|
39
37
  ts.deploy_keys_destroy_task_name
40
38
  }
41
- task Tasks::PullRequests::Merge,
42
- argument_names: %i[branch_name commit_message],
43
- branch_name: RakeFactory::DynamicValue.new { |ts|
44
- ts.branch_name
45
- },
46
- commit_message: RakeFactory::DynamicValue.new { |ts|
47
- ts.commit_message
48
- }
39
+ task Tasks::PullRequests::Merge
49
40
 
50
41
  def define_on(application)
51
42
  around_define(application) do
@@ -3,6 +3,9 @@
3
3
  require 'rake_factory'
4
4
  require 'octokit'
5
5
 
6
+ require_relative '../../exceptions/no_pull_request'
7
+ require_relative '../../exceptions/required_argument_unset'
8
+
6
9
  module RakeGithub
7
10
  module Tasks
8
11
  module PullRequests
@@ -12,41 +15,57 @@ module RakeGithub
12
15
  "#{t.repository} repository"
13
16
  end)
14
17
 
15
- default_argument_names %i[branch_name commit_message]
18
+ parameter :default_argument_names,
19
+ default: %i[branch_name commit_message]
16
20
 
17
21
  parameter :repository, required: true
18
22
  parameter :access_token, required: true
19
- parameter :branch_name, required: true
20
- parameter :commit_message, default: '%s'
21
23
 
22
- action do |t, _args|
24
+ def argument_names
25
+ @argument_names + default_argument_names
26
+ end
27
+
28
+ action do |t, args|
29
+ branch_name = resolve_branch_name(args)
30
+ commit_message = resolve_commit_message(args)
31
+
23
32
  client = Octokit::Client.new(access_token: access_token)
24
33
 
25
34
  open_prs = client.pull_requests(t.repository)
26
- current_pr = open_prs.find { |pr| pr[:head][:ref] == t.branch_name }
35
+ current_pr = open_prs.find { |pr| pr[:head][:ref] == branch_name }
27
36
 
28
- raise NoPullRequestError, t.branch_name if current_pr.nil?
37
+ # rubocop:disable Style/RaiseArgs
38
+ raise Exceptions::NoPullRequest.new(branch_name) if current_pr.nil?
39
+ # rubocop:enable Style/RaiseArgs
29
40
 
30
41
  client.merge_pull_request(
31
42
  t.repository,
32
43
  current_pr[:number],
33
- format(t.commit_message, current_pr[:title])
44
+ format(commit_message, current_pr[:title])
34
45
  )
35
46
  end
36
- end
37
- end
38
- end
39
- end
40
47
 
41
- class NoPullRequestError < StandardError
42
- attr_reader :branch_name
48
+ private
43
49
 
44
- def initialize(branch_name)
45
- super()
46
- @branch_name = branch_name
47
- end
50
+ def resolve_branch_name(args)
51
+ if !args.branch_name || args.branch_name.strip.empty?
52
+ raise(
53
+ Exceptions::RequiredArgumentUnset,
54
+ 'Must provide a branch name argument.'
55
+ )
56
+ end
57
+
58
+ args.branch_name.strip
59
+ end
48
60
 
49
- def message
50
- format('No pull request associated with branch %s', branch_name)
61
+ def resolve_commit_message(args)
62
+ if !args.commit_message || args.commit_message.strip.empty?
63
+ '%s'
64
+ else
65
+ args.commit_message.strip
66
+ end
67
+ end
68
+ end
69
+ end
51
70
  end
52
71
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RakeGithub
4
- VERSION = '0.12.0.pre.5'
4
+ VERSION = '0.12.0.pre.6'
5
5
  end
data/lib/rake_github.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rake_github/exceptions'
3
4
  require 'rake_github/version'
4
5
  require 'rake_github/tasks'
5
6
  require 'rake_github/task_sets'
data/rake_github.gemspec CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.required_ruby_version = '>= 2.7'
37
37
 
38
38
  spec.add_dependency 'colored2', '~> 3.1'
39
- spec.add_dependency 'octokit', '>= 4.16', '< 8.0'
39
+ spec.add_dependency 'octokit', '>= 4.16', '< 9.0'
40
40
  spec.add_dependency 'rake_factory', '~> 0.23'
41
41
  spec.add_dependency 'sshkey', '~> 2.0'
42
42
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rake_github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0.pre.5
4
+ version: 0.12.0.pre.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - InfraBlocks Maintainers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-31 00:00:00.000000000 Z
11
+ date: 2023-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '4.16'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '8.0'
36
+ version: '9.0'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '4.16'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: '8.0'
46
+ version: '9.0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake_factory
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -312,6 +312,9 @@ files:
312
312
  - bin/console
313
313
  - bin/setup
314
314
  - lib/rake_github.rb
315
+ - lib/rake_github/exceptions.rb
316
+ - lib/rake_github/exceptions/no_pull_request.rb
317
+ - lib/rake_github/exceptions/required_argument_unset.rb
315
318
  - lib/rake_github/task_sets.rb
316
319
  - lib/rake_github/task_sets/deploy_keys.rb
317
320
  - lib/rake_github/task_sets/repository.rb