github-to-canvas 0.0.22 → 0.0.23
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 +31 -9
- data/lib/github-to-canvas.rb +12 -3
- data/lib/github-to-canvas/canvas_interface.rb +10 -1
- data/lib/github-to-canvas/create_canvas_lesson.rb +4 -4
- data/lib/github-to-canvas/github_interface.rb +1 -1
- data/lib/github-to-canvas/repository_converter.rb +9 -1
- data/lib/github-to-canvas/update_canvas_lesson.rb +4 -4
- 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: a883cc9d8163795840e4d49334c15a3610d7bf95f03ea2791b03ef0311d235d7
|
4
|
+
data.tar.gz: deb4ee908fe26df4255626f10b6e1ae9dc5a1ffd993e24b8cac399f835eb87ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cea54b28ccb0d3e6ffaaf6d271fe5e4317ca92d86abe3958c97c8b1415571e25fed4cddb7317936727575f6696b0d32a3985294d893e7c48851f1ea33b3d210
|
7
|
+
data.tar.gz: 20af85bf1dc7f8c25a6ff3fb247717d611f6fb74d24716ee96966ec1573fc12516e6223fd4099d0022adbf565ca79b233679976319b4673fb3d4e0a31da59ffb
|
data/bin/github-to-canvas
CHANGED
@@ -19,6 +19,7 @@ OptionParser.new do |opts|
|
|
19
19
|
github-to-canvas --create COURSE [--branch BRANCH] [--name NAME] [--type TYPE]
|
20
20
|
github-to-canvas --create COURSE [--dry-run]
|
21
21
|
github-to-canvas --create COURSE [--fis-links]
|
22
|
+
github-to-canvas --create COURSE [--fis-links] [--remove-header]
|
22
23
|
github-to-canvas --align
|
23
24
|
github-to-canvas --align [--branch BRANCH]
|
24
25
|
github-to-canvas --align [--branch BRANCH] [--fis-links]
|
@@ -30,12 +31,13 @@ OptionParser.new do |opts|
|
|
30
31
|
|
31
32
|
Example usage:
|
32
33
|
|
33
|
-
github-to-canvas --create 154 -> Creates a lesson in course 154,
|
34
|
-
github-to-canvas --create 154 --name "Fetch Lab" -> Creates a lesson in course 154 with the provided name,
|
34
|
+
github-to-canvas --create 154 -> Creates a lesson in course 154, derives the name and type from the local repo
|
35
|
+
github-to-canvas --create 154 --name "Fetch Lab" -> Creates a lesson in course 154 with the provided name, derives the type from the local repo
|
35
36
|
github-to-canvas --create 154 --name "Fetch Lab" --type assignment -> Creates an assignment in course 154 with the provided name
|
36
|
-
github-to-canvas --create 154 --name "Fetch Lab" --branch solution -> Creates a lesson in course 154 with the provided name,
|
37
|
+
github-to-canvas --create 154 --name "Fetch Lab" --branch solution -> Creates a lesson in course 154 with the provided name, uses the repository's solution branch and derives the type from the local repo
|
37
38
|
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,
|
39
|
+
github-to-canvas --align --fis-links -> Patches existing lessons in Canvas based on the .canvas file, adds addition Flatiron School specific HTML
|
40
|
+
github-to-canvas --align --remove-header -> Patches existing lessons in Canvas based on the .canvas file, removes top lesson header before converting to HTML
|
39
41
|
|
40
42
|
EOBANNER
|
41
43
|
|
@@ -54,7 +56,7 @@ OptionParser.new do |opts|
|
|
54
56
|
end
|
55
57
|
opts.on("-tTYPE", "--type TYPE",
|
56
58
|
"Sets the type Canvas lesson to be created (page or assignment). If no type, type decided based on repository structure") do |type|
|
57
|
-
if type == 'page' || type == 'assignment'
|
59
|
+
if type == 'page' || type == 'assignment' || type == 'discussion'
|
58
60
|
options[:type] = type
|
59
61
|
else
|
60
62
|
puts "Invalid type. Defaulting to page"
|
@@ -70,13 +72,17 @@ OptionParser.new do |opts|
|
|
70
72
|
options[:version] = true
|
71
73
|
end
|
72
74
|
opts.on("-d", "--dry-run",
|
73
|
-
"Runs through creation without pushing to Canvas or GitHub") do |
|
75
|
+
"Runs through creation without pushing to Canvas or GitHub") do |d|
|
74
76
|
options[:dry] = true
|
75
77
|
end
|
76
78
|
opts.on("-f", "--fis-links",
|
77
|
-
"Adds additional Flatiron School HTML after markdown conversion") do |
|
79
|
+
"Adds additional Flatiron School HTML after markdown conversion") do |f|
|
78
80
|
options[:fis] = true
|
79
81
|
end
|
82
|
+
opts.on("-r", "--remove-header",
|
83
|
+
"Removes top lesson header before converting to HTML") do |r|
|
84
|
+
options[:remove_header] = true
|
85
|
+
end
|
80
86
|
|
81
87
|
end.parse!
|
82
88
|
|
@@ -101,9 +107,25 @@ if !options[:name]
|
|
101
107
|
end
|
102
108
|
|
103
109
|
if options[:create]
|
104
|
-
GithubToCanvas.new(mode: "create",
|
110
|
+
GithubToCanvas.new(mode: "create",
|
111
|
+
course: options[:course],
|
112
|
+
filepath: Dir.pwd,
|
113
|
+
branch: options[:branch],
|
114
|
+
name: options[:name],
|
115
|
+
type: options[:type],
|
116
|
+
dry: !!options[:dry],
|
117
|
+
fis_links: !!options[:fis],
|
118
|
+
remove_header: !!options[:remove_header])
|
105
119
|
end
|
106
120
|
|
107
121
|
if options[:align]
|
108
|
-
GithubToCanvas.new(mode: "align",
|
122
|
+
GithubToCanvas.new(mode: "align",
|
123
|
+
course: nil,
|
124
|
+
filepath: Dir.pwd,
|
125
|
+
branch: options[:branch],
|
126
|
+
name: options[:name],
|
127
|
+
type: options[:type],
|
128
|
+
dry: !!options[:dry],
|
129
|
+
fis_links: !!options[:fis],
|
130
|
+
remove_header: !!options[:remove_header])
|
109
131
|
end
|
data/lib/github-to-canvas.rb
CHANGED
@@ -9,7 +9,16 @@ require_relative './github-to-canvas/version'
|
|
9
9
|
|
10
10
|
class GithubToCanvas
|
11
11
|
|
12
|
-
def initialize(mode:,
|
12
|
+
def initialize(mode:,
|
13
|
+
course:,
|
14
|
+
filepath:Dir.pwd,
|
15
|
+
branch:'master',
|
16
|
+
name:File.basename(Dir.getwd),
|
17
|
+
type:"page",
|
18
|
+
dry:false,
|
19
|
+
fis_links:false,
|
20
|
+
remove_header:false)
|
21
|
+
|
13
22
|
if mode == 'version'
|
14
23
|
puts VERSION
|
15
24
|
return
|
@@ -17,12 +26,12 @@ class GithubToCanvas
|
|
17
26
|
|
18
27
|
if mode == 'create'
|
19
28
|
puts "github-to-canvas will now create a Canvas lesson based on the current repo"
|
20
|
-
CreateCanvasLesson.new(course, filepath, branch, name, type, dry, fis_links)
|
29
|
+
CreateCanvasLesson.new(course, filepath, branch, name, type, dry, fis_links, remove_header)
|
21
30
|
end
|
22
31
|
|
23
32
|
if mode == 'align'
|
24
33
|
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, fis_links)
|
34
|
+
UpdateCanvasLesson.new(filepath, branch, name, type, dry, fis_links, remove_header)
|
26
35
|
end
|
27
36
|
end
|
28
37
|
|
@@ -17,7 +17,11 @@ class CanvasInterface
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.push_to_canvas(course_id, type, name, new_readme)
|
20
|
-
|
20
|
+
if type == 'discussion'
|
21
|
+
url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}_topics"
|
22
|
+
else
|
23
|
+
url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}s"
|
24
|
+
end
|
21
25
|
payload = self.build_payload(type, name, new_readme)
|
22
26
|
begin
|
23
27
|
RestClient.post(url, payload, headers={
|
@@ -46,6 +50,11 @@ class CanvasInterface
|
|
46
50
|
'assignment[name]' => name,
|
47
51
|
'assignment[description]' => new_readme
|
48
52
|
}
|
53
|
+
elsif type == "discussion"
|
54
|
+
payload = {
|
55
|
+
'title' => name,
|
56
|
+
'message' => new_readme
|
57
|
+
}
|
49
58
|
else
|
50
59
|
payload = {
|
51
60
|
'wiki_page[title]' => name,
|
@@ -1,18 +1,18 @@
|
|
1
1
|
class CreateCanvasLesson
|
2
2
|
|
3
|
-
def initialize(course, filepath, branch, name, type, dry_run, fis_links)
|
3
|
+
def initialize(course, filepath, branch, name, type, dry_run, fis_links, remove_header)
|
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, fis_links)
|
10
|
+
create_canvas_lesson(original_readme, course, filepath, branch, name, type, dry_run, fis_links, remove_header)
|
11
11
|
end
|
12
12
|
|
13
|
-
def create_canvas_lesson(readme, course, filepath, branch, name, type, dry_run, fis_links)
|
13
|
+
def create_canvas_lesson(readme, course, filepath, branch, name, type, dry_run, fis_links, remove_header)
|
14
14
|
GithubInterface.get_updated_repo(filepath, branch)
|
15
|
-
new_readme = RepositoryConverter.convert(filepath, readme, branch)
|
15
|
+
new_readme = RepositoryConverter.convert(filepath, readme, branch, remove_header)
|
16
16
|
if fis_links
|
17
17
|
new_readme = RepositoryConverter.add_fis_links(filepath, new_readme)
|
18
18
|
end
|
@@ -19,7 +19,7 @@ class GithubInterface
|
|
19
19
|
def self.git_co_branch(filepath, branch)
|
20
20
|
self.cd_into_and(filepath, "git checkout #{branch}")
|
21
21
|
current_branch = self.get_current_branch(filepath)
|
22
|
-
|
22
|
+
puts "Current branch #{current_branch.strip}"
|
23
23
|
if !current_branch.match(branch)
|
24
24
|
puts "#{branch} branch not found. Exiting..."
|
25
25
|
abort
|
@@ -1,11 +1,19 @@
|
|
1
1
|
require 'redcarpet'
|
2
|
+
require 'byebug'
|
2
3
|
class RepositoryConverter
|
3
4
|
|
4
|
-
def self.convert(filepath, readme, branch)
|
5
|
+
def self.convert(filepath, readme, branch, remove_header)
|
6
|
+
if remove_header
|
7
|
+
self.remove_header(readme)
|
8
|
+
end
|
5
9
|
self.fix_local_images(filepath, readme, branch)
|
6
10
|
self.convert_to_html(filepath, readme)
|
7
11
|
end
|
8
12
|
|
13
|
+
def self.remove_header(readme)
|
14
|
+
readme.gsub!(/^#.+?\n\n/,"")
|
15
|
+
end
|
16
|
+
|
9
17
|
def self.fix_local_images(filepath, readme, branch)
|
10
18
|
raw_remote_url = self.set_raw_image_remote_url(filepath)
|
11
19
|
self.adjust_local_markdown_images(readme, raw_remote_url, branch)
|
@@ -1,18 +1,18 @@
|
|
1
1
|
class UpdateCanvasLesson
|
2
2
|
|
3
|
-
def initialize(filepath, branch, name, type, dry_run, fis_links)
|
3
|
+
def initialize(filepath, branch, name, type, dry_run, fis_links, remove_header)
|
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, fis_links)
|
10
|
+
update_canvas_lesson(readme, filepath, branch, name, type, dry_run, fis_links, remove_header)
|
11
11
|
end
|
12
12
|
|
13
|
-
def update_canvas_lesson(readme, filepath, branch, name, type, dry_run, fis_links)
|
13
|
+
def update_canvas_lesson(readme, filepath, branch, name, type, dry_run, fis_links, remove_header)
|
14
14
|
GithubInterface.get_updated_repo(filepath, branch)
|
15
|
-
new_readme = RepositoryConverter.convert(filepath, readme, branch)
|
15
|
+
new_readme = RepositoryConverter.convert(filepath, readme, branch, remove_header)
|
16
16
|
if fis_links
|
17
17
|
new_readme = RepositoryConverter.add_fis_links(filepath, new_readme)
|
18
18
|
end
|