Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 9e743a2

Browse files
authored
Standardize (#2)
1 parent d4ab15b commit 9e743a2

File tree

3 files changed

+85
-82
lines changed

3 files changed

+85
-82
lines changed

lib/errbit_github_plugin.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def self.root
1010
end
1111

1212
def self.read_static_file(file)
13-
File.read(File.join(self.root, "static", file))
13+
File.read(File.join(root, "static", file))
1414
end
1515
end
1616

lib/errbit_github_plugin/issue_tracker.rb

+26-22
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
module ErrbitGithubPlugin
66
class IssueTracker < ErrbitPlugin::IssueTracker
7-
LABEL = 'github'
7+
LABEL = "github"
88

9-
NOTE = 'Please configure your github repository in the <strong>GITHUB ' \
10-
'REPO</strong> field above.<br/> Instead of providing your ' \
11-
'username & password, you can link your Github account to your ' \
12-
'user profile, and allow Errbit to create issues using your ' \
13-
'OAuth token.'
9+
NOTE = "Please configure your github repository in the <strong>GITHUB " \
10+
"REPO</strong> field above.<br/> Instead of providing your " \
11+
"username & password, you can link your Github account to your " \
12+
"user profile, and allow Errbit to create issues using your " \
13+
"OAuth token."
1414

1515
FIELDS = {
1616
username: {
@@ -36,13 +36,13 @@ def self.fields
3636
def self.icons
3737
@icons ||= {
3838
create: [
39-
'image/png', ErrbitGithubPlugin.read_static_file('github_create.png')
39+
"image/png", ErrbitGithubPlugin.read_static_file("github_create.png")
4040
],
4141
goto: [
42-
'image/png', ErrbitGithubPlugin.read_static_file('github_goto.png'),
42+
"image/png", ErrbitGithubPlugin.read_static_file("github_goto.png")
4343
],
4444
inactive: [
45-
'image/png', ErrbitGithubPlugin.read_static_file('github_inactive.png'),
45+
"image/png", ErrbitGithubPlugin.read_static_file("github_inactive.png")
4646
]
4747
}
4848
end
@@ -57,11 +57,11 @@ def url
5757

5858
def errors
5959
errors = []
60-
if self.class.fields.detect {|f| options[f[0]].blank? }
61-
errors << [:base, 'You must specify your GitHub username and password']
60+
if self.class.fields.detect { |f| options[f[0]].blank? }
61+
errors << [:base, "You must specify your GitHub username and password"]
6262
end
6363
if repo.blank?
64-
errors << [:base, 'You must specify your GitHub repository url.']
64+
errors << [:base, "You must specify your GitHub repository url."]
6565
end
6666
errors
6767
end
@@ -71,12 +71,14 @@ def repo
7171
end
7272

7373
def create_issue(title, body, user: {})
74-
if user['github_login'] && user['github_oauth_token']
75-
github_client = Octokit::Client.new(
76-
login: user['github_login'], access_token: user['github_oauth_token'])
74+
github_client = if user["github_login"] && user["github_oauth_token"]
75+
Octokit::Client.new(
76+
login: user["github_login"], access_token: user["github_oauth_token"]
77+
)
7778
else
78-
github_client = Octokit::Client.new(
79-
login: options['username'], password: options['password'])
79+
Octokit::Client.new(
80+
login: options["username"], password: options["password"]
81+
)
8082
end
8183
issue = github_client.create_issue(repo, title, body)
8284
issue.html_url
@@ -85,12 +87,14 @@ def create_issue(title, body, user: {})
8587
end
8688

8789
def close_issue(url, user: {})
88-
if user['github_login'] && user['github_oauth_token']
89-
github_client = Octokit::Client.new(
90-
login: user['github_login'], access_token: user['github_oauth_token'])
90+
github_client = if user["github_login"] && user["github_oauth_token"]
91+
Octokit::Client.new(
92+
login: user["github_login"], access_token: user["github_oauth_token"]
93+
)
9194
else
92-
github_client = Octokit::Client.new(
93-
login: options['username'], password: options['password'])
95+
Octokit::Client.new(
96+
login: options["username"], password: options["password"]
97+
)
9498
end
9599
# It would be better to get the number from issue.number when we create the issue,
96100
# however, since we only have the url, get the number from it.

spec/issue_tracker_spec.rb

+58-59
Original file line numberDiff line numberDiff line change
@@ -1,175 +1,174 @@
11
# frozen_string_literal: true
22

33
RSpec.describe ErrbitGithubPlugin::IssueTracker do
4-
describe '.label' do
5-
it 'return LABEL' do
4+
describe ".label" do
5+
it "return LABEL" do
66
expect(described_class.label).to eq described_class::LABEL
77
end
88
end
99

10-
describe '.note' do
11-
it 'return NOTE' do
10+
describe ".note" do
11+
it "return NOTE" do
1212
expect(described_class.note).to eq described_class::NOTE
1313
end
1414
end
1515

16-
describe '.fields' do
17-
it 'return FIELDS' do
16+
describe ".fields" do
17+
it "return FIELDS" do
1818
expect(described_class.fields).to eq described_class::FIELDS
1919
end
2020
end
2121

22-
describe '.icons' do
23-
24-
it 'puts create icon onto the icons' do
25-
expect(described_class.icons[:create][0]).to eq 'image/png'
22+
describe ".icons" do
23+
it "puts create icon onto the icons" do
24+
expect(described_class.icons[:create][0]).to eq "image/png"
2625
expect(
2726
described_class.icons[:create][1]
28-
).to eq ErrbitGithubPlugin.read_static_file('github_create.png')
27+
).to eq ErrbitGithubPlugin.read_static_file("github_create.png")
2928
end
3029

31-
it 'puts goto icon onto the icons' do
32-
expect(described_class.icons[:goto][0]).to eq 'image/png'
30+
it "puts goto icon onto the icons" do
31+
expect(described_class.icons[:goto][0]).to eq "image/png"
3332
expect(
3433
described_class.icons[:goto][1]
35-
).to eq ErrbitGithubPlugin.read_static_file('github_goto.png')
34+
).to eq ErrbitGithubPlugin.read_static_file("github_goto.png")
3635
end
3736

38-
it 'puts inactive icon onto the icons' do
39-
expect(described_class.icons[:inactive][0]).to eq 'image/png'
37+
it "puts inactive icon onto the icons" do
38+
expect(described_class.icons[:inactive][0]).to eq "image/png"
4039
expect(
4140
described_class.icons[:inactive][1]
42-
).to eq ErrbitGithubPlugin.read_static_file('github_inactive.png')
41+
).to eq ErrbitGithubPlugin.read_static_file("github_inactive.png")
4342
end
4443
end
4544

4645
let(:tracker) { described_class.new(options) }
4746

48-
describe '#configured?' do
49-
context 'with errors' do
50-
let(:options) { { invalid_key: '' } }
47+
describe "#configured?" do
48+
context "with errors" do
49+
let(:options) { {invalid_key: ""} }
5150

52-
it 'return false' do
51+
it "return false" do
5352
expect(tracker.configured?).to eq false
5453
end
5554
end
56-
context 'without errors' do
55+
context "without errors" do
5756
let(:options) do
58-
{ username: 'foo', password: 'bar', github_repo: 'user/repos' }
57+
{username: "foo", password: "bar", github_repo: "user/repos"}
5958
end
6059

61-
it 'return true' do
60+
it "return true" do
6261
expect(tracker.configured?).to eq true
6362
end
6463
end
6564
end
6665

67-
describe '#url' do
68-
let(:options) { { github_repo: 'repo' } }
66+
describe "#url" do
67+
let(:options) { {github_repo: "repo"} }
6968

70-
it 'returns issues url' do
71-
expect(tracker.url).to eq 'https://github.com/repo/issues'
69+
it "returns issues url" do
70+
expect(tracker.url).to eq "https://github.com/repo/issues"
7271
end
7372
end
7473

75-
describe '#errors' do
74+
describe "#errors" do
7675
subject { tracker.errors }
7776

78-
context 'without username' do
79-
let(:options) { { username: '', password: 'bar', github_repo: 'repo' } }
77+
context "without username" do
78+
let(:options) { {username: "", password: "bar", github_repo: "repo"} }
8079

8180
it { is_expected.not_to be_empty }
8281
end
8382

84-
context 'without password' do
83+
context "without password" do
8584
let(:options) do
86-
{ username: '', password: 'bar', github_repo: 'repo' }
85+
{username: "", password: "bar", github_repo: "repo"}
8786
end
8887

8988
it { is_expected.not_to be_empty }
9089
end
9190

92-
context 'without github_repo' do
91+
context "without github_repo" do
9392
let(:options) do
94-
{ username: 'foo', password: 'bar', github_repo: '' }
93+
{username: "foo", password: "bar", github_repo: ""}
9594
end
9695

9796
it { is_expected.not_to be_empty }
9897
end
9998

100-
context 'with completed options' do
99+
context "with completed options" do
101100
let(:options) do
102-
{ username: 'foo', password: 'bar', github_repo: 'repo' }
101+
{username: "foo", password: "bar", github_repo: "repo"}
103102
end
104103

105104
it { is_expected.to be_empty }
106105
end
107106
end
108107

109-
describe '#repo' do
110-
let(:options) { { github_repo: 'baz' } }
108+
describe "#repo" do
109+
let(:options) { {github_repo: "baz"} }
111110

112-
it 'returns github repo' do
113-
expect(tracker.repo).to eq 'baz'
111+
it "returns github repo" do
112+
expect(tracker.repo).to eq "baz"
114113
end
115114
end
116115

117-
describe '#create_issue' do
118-
subject { tracker.create_issue('title', 'body', user: user) }
116+
describe "#create_issue" do
117+
subject { tracker.create_issue("title", "body", user: user) }
119118

120119
let(:options) do
121-
{ username: 'foo', password: 'bar', github_repo: 'user/repos' }
120+
{username: "foo", password: "bar", github_repo: "user/repos"}
122121
end
123122

124123
let(:fake_github_client) do
125-
double('Fake GitHub Client').tap do |github_client|
124+
double("Fake GitHub Client").tap do |github_client|
126125
expect(github_client).to receive(:create_issue).and_return(fake_issue)
127126
end
128127
end
129128

130129
let(:fake_issue) do
131-
double('Fake Issue').tap do |issue|
132-
expect(issue).to receive(:html_url).and_return('http://github.com/user/repos/issues/878').twice
130+
double("Fake Issue").tap do |issue|
131+
expect(issue).to receive(:html_url).and_return("http://github.com/user/repos/issues/878").twice
133132
end
134133
end
135134

136-
context 'signed in with token' do
135+
context "signed in with token" do
137136
let(:user) do
138137
{
139-
'github_login' => 'bob',
140-
'github_oauth_token' => 'valid_token'
138+
"github_login" => "bob",
139+
"github_oauth_token" => "valid_token"
141140
}
142141
end
143142

144-
it 'return issue url' do
143+
it "return issue url" do
145144
expect(Octokit::Client).to receive(:new)
146-
.with(login: user['github_login'], access_token: user['github_oauth_token'])
145+
.with(login: user["github_login"], access_token: user["github_oauth_token"])
147146
.and_return(fake_github_client)
148147

149148
expect(subject).to eq fake_issue.html_url
150149
end
151150
end
152151

153-
context 'signed in with password' do
152+
context "signed in with password" do
154153
let(:user) { {} }
155154

156-
it 'return issue url' do
155+
it "return issue url" do
157156
expect(Octokit::Client).to receive(:new)
158-
.with(login: options['username'], password: options['password'])
157+
.with(login: options["username"], password: options["password"])
159158
.and_return(fake_github_client)
160159

161160
expect(subject).to eq fake_issue.html_url
162161
end
163162
end
164163

165-
context 'when unauthentication error' do
164+
context "when unauthentication error" do
166165
let(:user) do
167-
{ 'github_login' => 'alice', 'github_oauth_token' => 'invalid_token' }
166+
{"github_login" => "alice", "github_oauth_token" => "invalid_token"}
168167
end
169168

170-
it 'raise AuthenticationError' do
169+
it "raise AuthenticationError" do
171170
expect(Octokit::Client).to receive(:new)
172-
.with(login: user['github_login'], access_token: user['github_oauth_token'])
171+
.with(login: user["github_login"], access_token: user["github_oauth_token"])
173172
.and_raise(Octokit::Unauthorized)
174173

175174
expect { subject }.to raise_error

0 commit comments

Comments
 (0)