Skip to content

Commit 9d24372

Browse files
authored
Merge pull request #7 from increments/add-search-issues
Add `search issues` command and refactoring
2 parents 20943ca + f33079f commit 9d24372

22 files changed

+401
-137
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
- package-ecosystem: "bundler"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"

.github/workflows/test.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
rspec:
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
ruby: ["2.7", "3.0", "3.1"]
19+
runs-on: "ubuntu-latest"
20+
continue-on-error: false
21+
steps:
22+
- uses: actions/checkout@v3
23+
- uses: ruby/setup-ruby@v1
24+
with:
25+
ruby-version: ${{ matrix.ruby }}
26+
bundler-cache: true
27+
- run: bundle exec rspec
28+
29+
rubocop:
30+
runs-on: "ubuntu-latest"
31+
steps:
32+
- uses: actions/checkout@v3
33+
- uses: ruby/setup-ruby@v1
34+
with:
35+
ruby-version: "3.1"
36+
bundler-cache: true
37+
- run: bundle exec rubocop

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ tmp
2020
*.o
2121
*.a
2222
mkmf.log
23+
vendor/bundle/

.rubocop.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
inherit_from: .rubocop_todo.yml
2+
3+
require:
4+
- rubocop-performance
5+
- rubocop-rspec
6+
- rubocop-rake
7+
8+
AllCops:
9+
NewCops: enable

.rubocop_todo.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config --exclude-limit 99999`
3+
# on 2022-10-12 04:57:08 UTC using RuboCop version 1.36.0.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 1
10+
# Configuration parameters: Include.
11+
# Include: **/*.gemspec
12+
Gemspec/RequiredRubyVersion:
13+
Exclude:
14+
- 'ruboty-github.gemspec'
15+
16+
# Offense count: 1
17+
Lint/UnreachableCode:
18+
Exclude:
19+
- 'lib/ruboty/github/actions/close_issue.rb'
20+
21+
# Offense count: 1
22+
# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes.
23+
Metrics/AbcSize:
24+
Max: 24
25+
26+
# Offense count: 2
27+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
28+
Metrics/MethodLength:
29+
Max: 14
30+
31+
# Offense count: 2
32+
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
33+
# NamePrefix: is_, has_, have_
34+
# ForbiddenPrefixes: is_, has_, have_
35+
# AllowedMethods: is_a?
36+
# MethodDefinitionMacros: define_method, define_singleton_method
37+
Naming/PredicateName:
38+
Exclude:
39+
- 'spec/**/*'
40+
- 'lib/ruboty/github/actions/base.rb'
41+
- 'lib/ruboty/github/actions/close_issue.rb'
42+
43+
# Offense count: 3
44+
# Configuration parameters: .
45+
# SupportedStyles: have_received, receive
46+
RSpec/MessageSpies:
47+
EnforcedStyle: receive
48+
49+
# Offense count: 2
50+
RSpec/MultipleExpectations:
51+
Max: 2
52+
53+
# Offense count: 11
54+
# Configuration parameters: AllowSubject.
55+
RSpec/MultipleMemoizedHelpers:
56+
Max: 13
57+
58+
# Offense count: 1
59+
RSpec/NoExpectationExample:
60+
Exclude:
61+
- 'spec/ruboty/handlers/github_spec.rb'
62+
63+
# Offense count: 9
64+
# Configuration parameters: AllowedConstants.
65+
Style/Documentation:
66+
Exclude:
67+
- 'spec/**/*'
68+
- 'test/**/*'
69+
- 'lib/ruboty/github/actions/base.rb'
70+
- 'lib/ruboty/github/actions/close_issue.rb'
71+
- 'lib/ruboty/github/actions/create_deploy_pull_request.rb'
72+
- 'lib/ruboty/github/actions/create_issue.rb'
73+
- 'lib/ruboty/github/actions/create_pull_request.rb'
74+
- 'lib/ruboty/github/actions/merge_pull_request.rb'
75+
- 'lib/ruboty/github/actions/remember.rb'
76+
- 'lib/ruboty/github/actions/search_issues.rb'
77+
- 'lib/ruboty/handlers/github.rb'
78+
79+
# Offense count: 1
80+
# This cop supports safe autocorrection (--autocorrect).
81+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
82+
# URISchemes: http, https
83+
Layout/LineLength:
84+
Max: 148

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Unreleased
2+
- Add `search issues` command
3+
- Support test on GitHub Actions
4+
- Add rubocop, rubocop-rake, rubocop-performance, rubocop-rspec gems
5+
- Use rubocop autocorrect and modify the code
6+
17
## 0.2.3
28
- Fix typo
39

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
# Specify your gem's dependencies in ruboty-github.gemspec

Rakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
require "bundler/gem_tasks"
1+
# frozen_string_literal: true
22

3+
require 'bundler/gem_tasks'

lib/ruboty/github.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
require "active_support/core_ext/string/strip"
2-
require "octokit"
1+
# frozen_string_literal: true
32

4-
require "ruboty"
5-
require "ruboty/github/actions/base"
6-
require "ruboty/github/actions/close_issue"
7-
require "ruboty/github/actions/create_issue"
8-
require "ruboty/github/actions/create_pull_request"
9-
require "ruboty/github/actions/create_deploy_pull_request"
10-
require "ruboty/github/actions/merge_pull_request"
11-
require "ruboty/github/actions/remember"
12-
require "ruboty/github/version"
13-
require "ruboty/handlers/github"
3+
require 'active_support/core_ext/string/strip'
4+
require 'octokit'
5+
6+
require 'ruboty'
7+
require 'ruboty/github/actions/base'
8+
require 'ruboty/github/actions/close_issue'
9+
require 'ruboty/github/actions/create_issue'
10+
require 'ruboty/github/actions/create_pull_request'
11+
require 'ruboty/github/actions/create_deploy_pull_request'
12+
require 'ruboty/github/actions/merge_pull_request'
13+
require 'ruboty/github/actions/remember'
14+
require 'ruboty/github/actions/search_issues'
15+
require 'ruboty/github/version'
16+
require 'ruboty/handlers/github'

lib/ruboty/github/actions/base.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# frozen_string_literal: true
2+
13
module Ruboty
24
module Github
35
module Actions
46
class Base
5-
NAMESPACE = "github"
7+
NAMESPACE = 'github'
68

79
attr_reader :message
810

@@ -17,7 +19,7 @@ def access_tokens
1719
end
1820

1921
def body
20-
message[:description] || ""
22+
message[:description] || ''
2123
end
2224

2325
def sender_name
@@ -45,14 +47,14 @@ def repository
4547
end
4648

4749
def client_options
48-
client_options_with_nil_value.reject {|key, value| value.nil? }
50+
client_options_with_nil_value.compact
4951
end
5052

5153
def client_options_with_nil_value
5254
{
5355
access_token: access_token,
5456
api_endpoint: api_endpoint,
55-
web_endpoint: web_endpoint,
57+
web_endpoint: web_endpoint
5658
}
5759
end
5860

@@ -66,11 +68,10 @@ def api_endpoint
6668

6769
# @note GITHUB_HOST will be deprecated on the next major version
6870
def github_base_url
69-
case
70-
when ENV["GITHUB_BASE_URL"]
71-
ENV["GITHUB_BASE_URL"]
72-
when ENV["GITHUB_HOST"]
73-
"https://#{ENV['GITHUB_HOST']}"
71+
if ENV.fetch('GITHUB_BASE_URL', nil)
72+
ENV.fetch('GITHUB_BASE_URL', nil)
73+
elsif ENV.fetch('GITHUB_HOST', nil)
74+
"https://#{ENV.fetch('GITHUB_HOST', nil)}"
7475
end
7576
end
7677
end

lib/ruboty/github/actions/close_issue.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1+
# frozen_string_literal: true
2+
13
module Ruboty
24
module Github
35
module Actions
46
class CloseIssue < Base
57
def call
6-
case
7-
when !has_access_token?
8+
if !has_access_token?
89
require_access_token
9-
when has_closed_issue_number?
10+
elsif has_closed_issue_number?
1011
reply_already_closed
1112
else
1213
close
1314
end
1415
rescue Octokit::Unauthorized
15-
message.reply("Failed in authentication (401)")
16+
message.reply('Failed in authentication (401)')
1617
rescue Octokit::NotFound
17-
message.reply("Could not find that issue")
18-
rescue => exception
19-
raise exception
20-
message.reply("Failed by #{exception.class}")
18+
message.reply('Could not find that issue')
19+
rescue StandardError => e
20+
raise e
21+
message.reply("Failed by #{e.class}")
2122
end
2223

2324
private
@@ -32,7 +33,7 @@ def request
3233
end
3334

3435
def has_closed_issue_number?
35-
issue.state == "closed"
36+
issue.state == 'closed'
3637
end
3738

3839
def reply_already_closed

lib/ruboty/github/actions/create_deploy_pull_request.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Ruboty
24
module Github
35
module Actions
@@ -7,28 +9,26 @@ class CreateDeployPullRequest < CreatePullRequest
79
def create
810
super
911

10-
if database_schema_changed?
11-
message.reply("@here :warning: This deployment includes some database migrations")
12-
end
12+
message.reply('@here :warning: This deployment includes some database migrations') if database_schema_changed?
1313
end
1414

1515
# e.g. master
1616
def to_branch
17-
to.split(":").last
17+
to.split(':').last
1818
end
1919

2020
def body
21-
lines = included_pull_requests.map do |pr|
22-
"- [##{pr[:number]}](#{pr[:html_url]}): #{pr[:title]} by @#{pr[:user][:login]}"
23-
end
24-
lines.unshift('## Pull Requests to deploy', '')
25-
lines.join("\n")
21+
lines = included_pull_requests.map do |pr|
22+
"- [##{pr[:number]}](#{pr[:html_url]}): #{pr[:title]} by @#{pr[:user][:login]}"
23+
end
24+
lines.unshift('## Pull Requests to deploy', '')
25+
lines.join("\n")
2626
end
2727

2828
def included_pull_requests
2929
numbers = comparison.commits.map do |commit|
3030
/^Merge pull request #(\d+) from/ =~ commit[:commit][:message]
31-
$1
31+
::Regexp.last_match(1)
3232
end
3333
numbers.compact.map { |number| client.pull_request(repository, number.to_i) }
3434
end

lib/ruboty/github/actions/create_issue.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Ruboty
24
module Github
35
module Actions
@@ -15,11 +17,11 @@ def call
1517
def create
1618
message.reply("Created #{issue.html_url}")
1719
rescue Octokit::Unauthorized
18-
message.reply("Failed in authentication (401)")
20+
message.reply('Failed in authentication (401)')
1921
rescue Octokit::NotFound
20-
message.reply("Could not find that repository")
21-
rescue => exception
22-
message.reply("Failed by #{exception.class}")
22+
message.reply('Could not find that repository')
23+
rescue StandardError => e
24+
message.reply("Failed by #{e.class}")
2325
end
2426

2527
def issue

0 commit comments

Comments
 (0)