github-to-canvas 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/github-to-canvas +13 -3
- data/lib/github-to-canvas.rb +3 -3
- data/lib/github-to-canvas/canvas_interface.rb +14 -7
- data/lib/github-to-canvas/create_canvas_lesson.rb +6 -3
- data/lib/github-to-canvas/github_interface.rb +13 -7
- data/lib/github-to-canvas/repository_converter.rb +17 -0
- data/lib/github-to-canvas/update_canvas_lesson.rb +6 -3
- data/lib/github-to-canvas/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30ee9448d74c258ca7d0a142e4b2fa4bfa708b227014fd3ef9cd5daf483b0da7
|
4
|
+
data.tar.gz: 84d2710f793fcf93beea70c5693554920b14890c0260e7d20bb28dbf1d3723c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75c3662d1354d1c5ed0e83ec625eed59010dc254ec9fa5663a060d7f32e58cf937ead936dabf8debd1e3f3f2d07f26747c17945b3a99fc3054244fea9be518b2
|
7
|
+
data.tar.gz: cbc3df60cb990b5c7fffd58b04a0a575c1ec2e4b513f68f7d080b724ee6da94726e14e4d405b77a38389ad1fe470b7c7b2fb03b8f40f00835bdbfebefe52c795
|
data/bin/github-to-canvas
CHANGED
@@ -18,8 +18,12 @@ OptionParser.new do |opts|
|
|
18
18
|
github-to-canvas --create COURSE [--branch BRANCH] [--name NAME]
|
19
19
|
github-to-canvas --create COURSE [--branch BRANCH] [--name NAME] [--type TYPE]
|
20
20
|
github-to-canvas --create COURSE [--dry-run]
|
21
|
+
github-to-canvas --create COURSE [--fis-links]
|
21
22
|
github-to-canvas --align
|
23
|
+
github-to-canvas --align [--branch BRANCH]
|
24
|
+
github-to-canvas --align [--branch BRANCH] [--fis-links]
|
22
25
|
github-to-canvas --version
|
26
|
+
|
23
27
|
|
24
28
|
Run these commands from inside a local GitHub repository. This gem is built for Flatiron School's internal use.
|
25
29
|
Some default behaviors assume this, like the default Canvas API path.
|
@@ -30,7 +34,9 @@ OptionParser.new do |opts|
|
|
30
34
|
github-to-canvas --create 154 --name "Fetch Lab" -> Creates a lesson in course 154 with the provided name, deriving the type from the local repo
|
31
35
|
github-to-canvas --create 154 --name "Fetch Lab" --type assignment -> Creates an assignment in course 154 with the provided name
|
32
36
|
github-to-canvas --create 154 --name "Fetch Lab" --branch solution -> Creates a lesson in course 154 with the provided name, using the repositorie's solution branch and deriving the type from the local repo
|
33
|
-
|
37
|
+
github-to-canvas --align -> Patches existing lessons in Canvas based on the .canvas file
|
38
|
+
github-to-canvas --align --fis-links -> Patches existing lessons in Canvas based on the .canvas file, adding addition Flatiron School specific HTML
|
39
|
+
|
34
40
|
EOBANNER
|
35
41
|
|
36
42
|
opts.on("-cCOURSE", "--create COURSE",
|
@@ -67,6 +73,10 @@ OptionParser.new do |opts|
|
|
67
73
|
"Runs through creation without pushing to Canvas or GitHub") do |v|
|
68
74
|
options[:dry] = true
|
69
75
|
end
|
76
|
+
opts.on("-f", "--fis-links",
|
77
|
+
"Adds additional Flatiron School HTML after markdown conversion") do |v|
|
78
|
+
options[:fis] = true
|
79
|
+
end
|
70
80
|
|
71
81
|
end.parse!
|
72
82
|
|
@@ -91,9 +101,9 @@ if !options[:name]
|
|
91
101
|
end
|
92
102
|
|
93
103
|
if options[:create]
|
94
|
-
GithubToCanvas.new(mode: "create", course: options[:course], filepath: Dir.pwd, branch: options[:branch], name: options[:name], type: options[:type], dry: !!options[:dry])
|
104
|
+
GithubToCanvas.new(mode: "create", course: options[:course], filepath: Dir.pwd, branch: options[:branch], name: options[:name], type: options[:type], dry: !!options[:dry], fis_links: !!options[:fis])
|
95
105
|
end
|
96
106
|
|
97
107
|
if options[:align]
|
98
|
-
GithubToCanvas.new(mode: "align", course: nil, filepath: Dir.pwd, branch: options[:branch], name: options[:name], type: options[:type], dry: !!options[:dry])
|
108
|
+
GithubToCanvas.new(mode: "align", course: nil, filepath: Dir.pwd, branch: options[:branch], name: options[:name], type: options[:type], dry: !!options[:dry], fis_links: !!options[:fis])
|
99
109
|
end
|
data/lib/github-to-canvas.rb
CHANGED
@@ -9,7 +9,7 @@ require_relative './github-to-canvas/version'
|
|
9
9
|
|
10
10
|
class GithubToCanvas
|
11
11
|
|
12
|
-
def initialize(mode:, course:, filepath:Dir.pwd, branch:'master', name:File.basename(Dir.getwd), type:"page", dry:false)
|
12
|
+
def initialize(mode:, course:, filepath:Dir.pwd, branch:'master', name:File.basename(Dir.getwd), type:"page", dry:false, fis_links:false)
|
13
13
|
if mode == 'version'
|
14
14
|
puts VERSION
|
15
15
|
return
|
@@ -17,12 +17,12 @@ class GithubToCanvas
|
|
17
17
|
|
18
18
|
if mode == 'create'
|
19
19
|
puts "github-to-canvas will now create a Canvas lesson based on the current repo"
|
20
|
-
CreateCanvasLesson.new(course, filepath, branch, name, type, dry)
|
20
|
+
CreateCanvasLesson.new(course, filepath, branch, name, type, dry, fis_links)
|
21
21
|
end
|
22
22
|
|
23
23
|
if mode == 'align'
|
24
24
|
puts "github-to-canvas will now align any existing Canvas lessons based on the current repo. NOTE: .canvas file must be present"
|
25
|
-
UpdateCanvasLesson.new(filepath, branch, name, type, dry)
|
25
|
+
UpdateCanvasLesson.new(filepath, branch, name, type, dry, fis_links)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -19,18 +19,25 @@ class CanvasInterface
|
|
19
19
|
def self.push_to_canvas(course_id, type, name, new_readme)
|
20
20
|
url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}s"
|
21
21
|
payload = self.build_payload(type, name, new_readme)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
begin
|
23
|
+
RestClient.post(url, payload, headers={
|
24
|
+
"Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
|
25
|
+
})
|
26
|
+
rescue
|
27
|
+
puts "Something went wrong while pushing lesson #{id} to course #{course_id}"
|
28
|
+
end
|
26
29
|
end
|
27
30
|
|
28
31
|
def self.update_existing_lesson(course_id, id, type, name, new_readme, dry_run)
|
29
32
|
url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}s/#{id}"
|
30
33
|
payload = self.build_payload(type, name, new_readme)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
begin
|
35
|
+
RestClient.put(url, payload, headers={
|
36
|
+
"Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
|
37
|
+
})
|
38
|
+
rescue
|
39
|
+
puts "Something went wrong while pushing lesson #{id} to course #{course_id}"
|
40
|
+
end
|
34
41
|
end
|
35
42
|
|
36
43
|
def self.build_payload(type, name, new_readme)
|
@@ -1,18 +1,21 @@
|
|
1
1
|
class CreateCanvasLesson
|
2
2
|
|
3
|
-
def initialize(course, filepath, branch, name, type, dry_run)
|
3
|
+
def initialize(course, filepath, branch, name, type, dry_run, fis_links)
|
4
4
|
name = name.split(/[- _]/).map(&:capitalize).join(' ')
|
5
5
|
original_readme = File.read("#{filepath}/README.md")
|
6
6
|
if !original_readme
|
7
7
|
puts 'README.md not found in current directory. Exiting...'
|
8
8
|
abort
|
9
9
|
end
|
10
|
-
create_canvas_lesson(original_readme, course, filepath, branch, name, type, dry_run)
|
10
|
+
create_canvas_lesson(original_readme, course, filepath, branch, name, type, dry_run, fis_links)
|
11
11
|
end
|
12
12
|
|
13
|
-
def create_canvas_lesson(readme, course, filepath, branch, name, type, dry_run)
|
13
|
+
def create_canvas_lesson(readme, course, filepath, branch, name, type, dry_run, fis_links)
|
14
14
|
GithubInterface.get_updated_repo(filepath, branch)
|
15
15
|
new_readme = RepositoryConverter.convert(filepath, readme, branch)
|
16
|
+
if fis_links
|
17
|
+
new_readme = RepositoryConverter.add_fis_links(filepath, new_readme)
|
18
|
+
end
|
16
19
|
response = CanvasInterface.submit_to_canvas(course, type, name, new_readme, dry_run)
|
17
20
|
if dry_run
|
18
21
|
puts 'DRY RUN: Skipping dotfile creation and push to GitHub'
|
@@ -1,20 +1,26 @@
|
|
1
|
-
|
1
|
+
require 'byebug'
|
2
2
|
class GithubInterface
|
3
3
|
|
4
|
+
def self.cd_into_and(filepath, command)
|
5
|
+
cmd = "cd #{filepath} && #{command}"
|
6
|
+
puts cmd
|
7
|
+
`#{cmd}`
|
8
|
+
end
|
9
|
+
|
4
10
|
def self.get_updated_repo(filepath, branch)
|
5
11
|
self.git_co_branch(filepath, branch)
|
6
12
|
self.git_pull(filepath, branch)
|
7
13
|
end
|
8
14
|
|
9
|
-
def self.
|
10
|
-
|
11
|
-
puts cmd
|
12
|
-
`#{cmd}`
|
15
|
+
def self.get_current_branch(filepath)
|
16
|
+
self.cd_into_and(filepath, "git rev-parse --abbrev-ref HEAD")
|
13
17
|
end
|
14
18
|
|
15
19
|
def self.git_co_branch(filepath, branch)
|
16
|
-
|
17
|
-
|
20
|
+
self.cd_into_and(filepath, "git checkout #{branch}")
|
21
|
+
current_branch = self.get_current_branch(filepath)
|
22
|
+
|
23
|
+
if !current_branch.match(branch)
|
18
24
|
puts "#{branch} branch not found. Exiting..."
|
19
25
|
abort
|
20
26
|
end
|
@@ -20,6 +20,13 @@ class RepositoryConverter
|
|
20
20
|
remote.strip!
|
21
21
|
end
|
22
22
|
|
23
|
+
def self.get_repo_url(filepath)
|
24
|
+
remote = GithubInterface.git_remote(filepath)
|
25
|
+
remote.gsub!("git@github.com:","https://github.com/")
|
26
|
+
remote.gsub!(/.git$/,"")
|
27
|
+
remote.strip!
|
28
|
+
end
|
29
|
+
|
23
30
|
def self.adjust_local_markdown_images(readme, raw_remote_url, branch)
|
24
31
|
readme.gsub!(/\!\[.+\]\(.+\)/) {|image|
|
25
32
|
if !image.match('amazonaws.com') && !image.match('https://') && !image.match('youtube')
|
@@ -52,4 +59,14 @@ class RepositoryConverter
|
|
52
59
|
redcarpet.render(readme)
|
53
60
|
end
|
54
61
|
|
62
|
+
def self.add_fis_links(filepath, readme)
|
63
|
+
repo = self.get_repo_url(filepath)
|
64
|
+
github_repo_link = "<a style='text-decoration: none;' href='#{repo}' target='_blank' rel='noopener'><img style='width: 40px; height: 40px; margin: 2px;' title='Open GitHub Repo' src='https://curriculum-content.s3.amazonaws.com/git-logo-gray.png' alt='Link to GitHub Repo' /></a>"
|
65
|
+
github_issue_link = "<a style='text-decoration: none;' href='#{repo}/issues/new' target='_blank' rel='noopener'><img style='width: 40px; height: 40px; margin: 2px;' title='Create New Issue' src='https://curriculum-content.s3.amazonaws.com/flag-icon-gray.png' alt='Link to GitHub Repo Issue Form' /></a>"
|
66
|
+
|
67
|
+
html = "<p style='margin: 0; padding: 0; position: absolute; right: 5px; top: 5px; margin: 0; padding: 0;'>#{github_repo_link}#{github_issue_link}</p>"
|
68
|
+
|
69
|
+
readme + html
|
70
|
+
end
|
71
|
+
|
55
72
|
end
|
@@ -1,18 +1,21 @@
|
|
1
1
|
class UpdateCanvasLesson
|
2
2
|
|
3
|
-
def initialize(filepath, branch, name, type, dry_run)
|
3
|
+
def initialize(filepath, branch, name, type, dry_run, fis_links)
|
4
4
|
name = name.split(/[- _]/).map(&:capitalize).join(' ')
|
5
5
|
readme = File.read("#{filepath}/README.md")
|
6
6
|
if !readme
|
7
7
|
puts 'README.md not found in current directory. Exiting...'
|
8
8
|
abort
|
9
9
|
end
|
10
|
-
update_canvas_lesson(readme, filepath, branch, name, type, dry_run)
|
10
|
+
update_canvas_lesson(readme, filepath, branch, name, type, dry_run, fis_links)
|
11
11
|
end
|
12
12
|
|
13
|
-
def update_canvas_lesson(readme, filepath, branch, name, type, dry_run)
|
13
|
+
def update_canvas_lesson(readme, filepath, branch, name, type, dry_run, fis_links)
|
14
14
|
GithubInterface.get_updated_repo(filepath, branch)
|
15
15
|
new_readme = RepositoryConverter.convert(filepath, readme, branch)
|
16
|
+
if fis_links
|
17
|
+
new_readme = RepositoryConverter.add_fis_links(filepath, new_readme)
|
18
|
+
end
|
16
19
|
canvas_data = CanvasDotfile.read_canvas_data
|
17
20
|
canvas_data[:lessons].each { |lesson|
|
18
21
|
CanvasInterface.update_existing_lesson(lesson[:course_id], lesson[:id], type, name, new_readme, dry_run)
|