Class: ErrbitGithubPlugin::IssueTracker

Inherits:
ErrbitPlugin::IssueTracker
  • Object
show all
Defined in:
lib/errbit_github_plugin/issue_tracker.rb

Constant Summary collapse

LABEL =
'github'
NOTE =
'Please configure your github repository in the <strong>GITHUB ' <<
'REPO</strong> field above.<br/> 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 => {
    :placeholder => "Your username on GitHub"
  },
  :password => {
    :placeholder => "Password for your account"
  }
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#oauth_tokenObject

Returns the value of attribute oauth_token.



43
44
45
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 43

def oauth_token
  @oauth_token
end

#urlObject (readonly)

Returns the value of attribute url.



44
45
46
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 44

def url
  @url
end

Class Method Details

.body_templateObject



35
36
37
38
39
40
41
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 35

def self.body_template
  @body_template ||= ERB.new(File.read(
    File.join(
      ErrbitGithubPlugin.root, 'views', 'github_issues_body.txt.erb'
    )
  ))
end

.fieldsObject



31
32
33
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 31

def self.fields
  FIELDS
end

.labelObject



23
24
25
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 23

def self.label
  LABEL
end

.noteObject



27
28
29
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 27

def self.note
  NOTE
end

Instance Method Details

#comments_allowed?Boolean

Returns:

  • (Boolean)


50
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 50

def comments_allowed?; false; end

#configured?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 46

def configured?
  project_id.present?
end

#create_issue(problem, reported_by = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 75

def create_issue(problem, reported_by = nil)
  begin
    issue = github_client.create_issue(
      project_id,
      "[#{ problem.environment }][#{ problem.where }] #{problem.message.to_s.truncate(100)}",
      self.class.body_template.result(binding).unpack('C*').pack('U*')
    )
    @url = issue.html_url
    problem.update_attributes(
      :issue_link => issue.html_url,
      :issue_type => self.class.label
    )

  rescue Octokit::Unauthorized
    raise ErrbitGithubPlugin::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password."
  end
end

#errorsObject



56
57
58
59
60
61
62
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 56

def errors
  errors = []
  if self.class.fields.detect {|f| params[f[0]].blank? }
    errors << [:base, 'You must specify your GitHub username and password']
  end
  errors
end

#github_clientObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 64

def github_client
  # Login using OAuth token, if given.
  if oauth_token
    Octokit::Client.new(
      :login => params['username'], :oauth_token => oauth_token)
  else
    Octokit::Client.new(
      :login => params['username'], :password => params['password'])
  end
end

#project_idObject



52
53
54
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 52

def project_id
  app.github_repo
end