-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathplugin.rb
49 lines (41 loc) · 1.6 KB
/
plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
# name: discourse-github
# about: Allows staff to assign badges to users based on GitHub contributions, and allows users to create Github Linkbacks and Permalinks
# meta_topic_id: 99895
# version: 0.3
# authors: Robin Ward, Sam Saffron
# url: https://github.com/discourse/discourse-github
gem "sawyer", "0.9.2"
gem "octokit", "5.6.1"
# Site setting validators must be loaded before initialize
require_relative "app/lib/github_badges_repo_setting_validator.rb"
require_relative "app/lib/github_linkback_access_token_setting_validator.rb"
enabled_site_setting :enable_discourse_github_plugin
after_initialize do
%w[
../app/models/github_commit.rb
../app/models/github_repo.rb
../app/lib/github_linkback.rb
../app/lib/github_badges.rb
../app/lib/github_permalinks.rb
../app/lib/commits_populator.rb
../app/jobs/regular/create_github_linkback.rb
../app/jobs/scheduled/grant_github_badges.rb
../app/jobs/regular/replace_github_non_permalinks.rb
].each { |path| require File.expand_path(path, __FILE__) }
on(:post_created) do |post|
if SiteSetting.github_linkback_enabled? && SiteSetting.enable_discourse_github_plugin?
GithubLinkback.new(post).enqueue
end
end
on(:post_edited) do |post|
if SiteSetting.github_linkback_enabled? && SiteSetting.enable_discourse_github_plugin?
GithubLinkback.new(post).enqueue
end
end
on(:before_post_process_cooked) do |doc, post|
if SiteSetting.github_permalinks_enabled? && SiteSetting.enable_discourse_github_plugin?
GithubPermalinks.replace_github_non_permalinks(post)
end
end
end