diff --git a/lib/errbit_github_plugin.rb b/lib/errbit_github_plugin.rb
index 25fcf8a..0a17647 100644
--- a/lib/errbit_github_plugin.rb
+++ b/lib/errbit_github_plugin.rb
@@ -10,7 +10,7 @@ def self.root
end
def self.read_static_file(file)
- File.read(File.join(self.root, "static", file))
+ File.read(File.join(root, "static", file))
end
end
diff --git a/lib/errbit_github_plugin/issue_tracker.rb b/lib/errbit_github_plugin/issue_tracker.rb
index ca9c53e..e4c31c1 100644
--- a/lib/errbit_github_plugin/issue_tracker.rb
+++ b/lib/errbit_github_plugin/issue_tracker.rb
@@ -4,13 +4,13 @@
module ErrbitGithubPlugin
class IssueTracker < ErrbitPlugin::IssueTracker
- LABEL = 'github'
+ LABEL = "github"
- NOTE = 'Please configure your github repository in the GITHUB ' \
- 'REPO field above.
Instead of providing your ' \
- 'username & password, you can link your Github account to your ' \
- 'user profile, and allow Errbit to create issues using your ' \
- 'OAuth token.'
+ NOTE = "Please configure your github repository in the GITHUB " \
+ "REPO field above.
Instead of providing your " \
+ "username & password, you can link your Github account to your " \
+ "user profile, and allow Errbit to create issues using your " \
+ "OAuth token."
FIELDS = {
username: {
@@ -36,13 +36,13 @@ def self.fields
def self.icons
@icons ||= {
create: [
- 'image/png', ErrbitGithubPlugin.read_static_file('github_create.png')
+ "image/png", ErrbitGithubPlugin.read_static_file("github_create.png")
],
goto: [
- 'image/png', ErrbitGithubPlugin.read_static_file('github_goto.png'),
+ "image/png", ErrbitGithubPlugin.read_static_file("github_goto.png")
],
inactive: [
- 'image/png', ErrbitGithubPlugin.read_static_file('github_inactive.png'),
+ "image/png", ErrbitGithubPlugin.read_static_file("github_inactive.png")
]
}
end
@@ -57,11 +57,11 @@ def url
def errors
errors = []
- if self.class.fields.detect {|f| options[f[0]].blank? }
- errors << [:base, 'You must specify your GitHub username and password']
+ if self.class.fields.detect { |f| options[f[0]].blank? }
+ errors << [:base, "You must specify your GitHub username and password"]
end
if repo.blank?
- errors << [:base, 'You must specify your GitHub repository url.']
+ errors << [:base, "You must specify your GitHub repository url."]
end
errors
end
@@ -71,12 +71,14 @@ def repo
end
def create_issue(title, body, user: {})
- if user['github_login'] && user['github_oauth_token']
- github_client = Octokit::Client.new(
- login: user['github_login'], access_token: user['github_oauth_token'])
+ github_client = if user["github_login"] && user["github_oauth_token"]
+ Octokit::Client.new(
+ login: user["github_login"], access_token: user["github_oauth_token"]
+ )
else
- github_client = Octokit::Client.new(
- login: options['username'], password: options['password'])
+ Octokit::Client.new(
+ login: options["username"], password: options["password"]
+ )
end
issue = github_client.create_issue(repo, title, body)
issue.html_url
@@ -85,12 +87,14 @@ def create_issue(title, body, user: {})
end
def close_issue(url, user: {})
- if user['github_login'] && user['github_oauth_token']
- github_client = Octokit::Client.new(
- login: user['github_login'], access_token: user['github_oauth_token'])
+ github_client = if user["github_login"] && user["github_oauth_token"]
+ Octokit::Client.new(
+ login: user["github_login"], access_token: user["github_oauth_token"]
+ )
else
- github_client = Octokit::Client.new(
- login: options['username'], password: options['password'])
+ Octokit::Client.new(
+ login: options["username"], password: options["password"]
+ )
end
# It would be better to get the number from issue.number when we create the issue,
# however, since we only have the url, get the number from it.
diff --git a/spec/issue_tracker_spec.rb b/spec/issue_tracker_spec.rb
index 4e4531a..54f2330 100644
--- a/spec/issue_tracker_spec.rb
+++ b/spec/issue_tracker_spec.rb
@@ -1,175 +1,174 @@
# frozen_string_literal: true
RSpec.describe ErrbitGithubPlugin::IssueTracker do
- describe '.label' do
- it 'return LABEL' do
+ describe ".label" do
+ it "return LABEL" do
expect(described_class.label).to eq described_class::LABEL
end
end
- describe '.note' do
- it 'return NOTE' do
+ describe ".note" do
+ it "return NOTE" do
expect(described_class.note).to eq described_class::NOTE
end
end
- describe '.fields' do
- it 'return FIELDS' do
+ describe ".fields" do
+ it "return FIELDS" do
expect(described_class.fields).to eq described_class::FIELDS
end
end
- describe '.icons' do
-
- it 'puts create icon onto the icons' do
- expect(described_class.icons[:create][0]).to eq 'image/png'
+ describe ".icons" do
+ it "puts create icon onto the icons" do
+ expect(described_class.icons[:create][0]).to eq "image/png"
expect(
described_class.icons[:create][1]
- ).to eq ErrbitGithubPlugin.read_static_file('github_create.png')
+ ).to eq ErrbitGithubPlugin.read_static_file("github_create.png")
end
- it 'puts goto icon onto the icons' do
- expect(described_class.icons[:goto][0]).to eq 'image/png'
+ it "puts goto icon onto the icons" do
+ expect(described_class.icons[:goto][0]).to eq "image/png"
expect(
described_class.icons[:goto][1]
- ).to eq ErrbitGithubPlugin.read_static_file('github_goto.png')
+ ).to eq ErrbitGithubPlugin.read_static_file("github_goto.png")
end
- it 'puts inactive icon onto the icons' do
- expect(described_class.icons[:inactive][0]).to eq 'image/png'
+ it "puts inactive icon onto the icons" do
+ expect(described_class.icons[:inactive][0]).to eq "image/png"
expect(
described_class.icons[:inactive][1]
- ).to eq ErrbitGithubPlugin.read_static_file('github_inactive.png')
+ ).to eq ErrbitGithubPlugin.read_static_file("github_inactive.png")
end
end
let(:tracker) { described_class.new(options) }
- describe '#configured?' do
- context 'with errors' do
- let(:options) { { invalid_key: '' } }
+ describe "#configured?" do
+ context "with errors" do
+ let(:options) { {invalid_key: ""} }
- it 'return false' do
+ it "return false" do
expect(tracker.configured?).to eq false
end
end
- context 'without errors' do
+ context "without errors" do
let(:options) do
- { username: 'foo', password: 'bar', github_repo: 'user/repos' }
+ {username: "foo", password: "bar", github_repo: "user/repos"}
end
- it 'return true' do
+ it "return true" do
expect(tracker.configured?).to eq true
end
end
end
- describe '#url' do
- let(:options) { { github_repo: 'repo' } }
+ describe "#url" do
+ let(:options) { {github_repo: "repo"} }
- it 'returns issues url' do
- expect(tracker.url).to eq 'https://github.com/repo/issues'
+ it "returns issues url" do
+ expect(tracker.url).to eq "https://github.com/repo/issues"
end
end
- describe '#errors' do
+ describe "#errors" do
subject { tracker.errors }
- context 'without username' do
- let(:options) { { username: '', password: 'bar', github_repo: 'repo' } }
+ context "without username" do
+ let(:options) { {username: "", password: "bar", github_repo: "repo"} }
it { is_expected.not_to be_empty }
end
- context 'without password' do
+ context "without password" do
let(:options) do
- { username: '', password: 'bar', github_repo: 'repo' }
+ {username: "", password: "bar", github_repo: "repo"}
end
it { is_expected.not_to be_empty }
end
- context 'without github_repo' do
+ context "without github_repo" do
let(:options) do
- { username: 'foo', password: 'bar', github_repo: '' }
+ {username: "foo", password: "bar", github_repo: ""}
end
it { is_expected.not_to be_empty }
end
- context 'with completed options' do
+ context "with completed options" do
let(:options) do
- { username: 'foo', password: 'bar', github_repo: 'repo' }
+ {username: "foo", password: "bar", github_repo: "repo"}
end
it { is_expected.to be_empty }
end
end
- describe '#repo' do
- let(:options) { { github_repo: 'baz' } }
+ describe "#repo" do
+ let(:options) { {github_repo: "baz"} }
- it 'returns github repo' do
- expect(tracker.repo).to eq 'baz'
+ it "returns github repo" do
+ expect(tracker.repo).to eq "baz"
end
end
- describe '#create_issue' do
- subject { tracker.create_issue('title', 'body', user: user) }
+ describe "#create_issue" do
+ subject { tracker.create_issue("title", "body", user: user) }
let(:options) do
- { username: 'foo', password: 'bar', github_repo: 'user/repos' }
+ {username: "foo", password: "bar", github_repo: "user/repos"}
end
let(:fake_github_client) do
- double('Fake GitHub Client').tap do |github_client|
+ double("Fake GitHub Client").tap do |github_client|
expect(github_client).to receive(:create_issue).and_return(fake_issue)
end
end
let(:fake_issue) do
- double('Fake Issue').tap do |issue|
- expect(issue).to receive(:html_url).and_return('http://github.com/user/repos/issues/878').twice
+ double("Fake Issue").tap do |issue|
+ expect(issue).to receive(:html_url).and_return("http://github.com/user/repos/issues/878").twice
end
end
- context 'signed in with token' do
+ context "signed in with token" do
let(:user) do
{
- 'github_login' => 'bob',
- 'github_oauth_token' => 'valid_token'
+ "github_login" => "bob",
+ "github_oauth_token" => "valid_token"
}
end
- it 'return issue url' do
+ it "return issue url" do
expect(Octokit::Client).to receive(:new)
- .with(login: user['github_login'], access_token: user['github_oauth_token'])
+ .with(login: user["github_login"], access_token: user["github_oauth_token"])
.and_return(fake_github_client)
expect(subject).to eq fake_issue.html_url
end
end
- context 'signed in with password' do
+ context "signed in with password" do
let(:user) { {} }
- it 'return issue url' do
+ it "return issue url" do
expect(Octokit::Client).to receive(:new)
- .with(login: options['username'], password: options['password'])
+ .with(login: options["username"], password: options["password"])
.and_return(fake_github_client)
expect(subject).to eq fake_issue.html_url
end
end
- context 'when unauthentication error' do
+ context "when unauthentication error" do
let(:user) do
- { 'github_login' => 'alice', 'github_oauth_token' => 'invalid_token' }
+ {"github_login" => "alice", "github_oauth_token" => "invalid_token"}
end
- it 'raise AuthenticationError' do
+ it "raise AuthenticationError" do
expect(Octokit::Client).to receive(:new)
- .with(login: user['github_login'], access_token: user['github_oauth_token'])
+ .with(login: user["github_login"], access_token: user["github_oauth_token"])
.and_raise(Octokit::Unauthorized)
expect { subject }.to raise_error