github-to-canvas 0.0.25 → 0.0.30
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 +32 -23
- data/lib/github-to-canvas.rb +5 -4
- data/lib/github-to-canvas/canvas_dotfile.rb +2 -3
- data/lib/github-to-canvas/canvas_interface.rb +13 -12
- data/lib/github-to-canvas/create_canvas_lesson.rb +14 -12
- data/lib/github-to-canvas/github_interface.rb +0 -1
- data/lib/github-to-canvas/repository_converter.rb +1 -1
- data/lib/github-to-canvas/update_canvas_lesson.rb +10 -9
- 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: 4848e1245f38fecc827a52b9148f89526d3b38045eb155d6b5eba412dcb96376
|
4
|
+
data.tar.gz: 1d414803e3fb134f82ecec3d2b21a80756b43000be3b69ea2df84fc7efedebb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e2d63fab8492b4486626a8bd09d0c748eed6f6dbd76c340c3277058a6d982f1d62388c6443acf2f490fb9b91a0b9aa6b7cd68e98168d3e24d56b22fea5915a3
|
7
|
+
data.tar.gz: f2ed3c42b44f75a629dce9d12bec144624102afb2c96148368e98cc9d6c2812fe26e2f6818fd41dc9d1a4c464b2ef8997c9801c467aa0829dffad191bab01172
|
data/bin/github-to-canvas
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'optparse'
|
4
4
|
require 'github-to-canvas'
|
5
|
-
|
6
5
|
options = {}
|
7
6
|
OptionParser.new do |opts|
|
8
7
|
opts.banner = <<-EOBANNER
|
@@ -13,13 +12,13 @@ OptionParser.new do |opts|
|
|
13
12
|
https://github.com/learn-co-curriculum/github-to-canvas
|
14
13
|
|
15
14
|
Commands:
|
16
|
-
github-to-canvas --create COURSE
|
17
|
-
github-to-canvas --create COURSE [--
|
18
|
-
github-to-canvas --create COURSE [--branch BRANCH]
|
19
|
-
github-to-canvas --create COURSE [--branch BRANCH] [--name NAME]
|
20
|
-
github-to-canvas --create COURSE [--
|
21
|
-
github-to-canvas --create COURSE [--fis-links]
|
22
|
-
github-to-canvas --create COURSE [--fis-links] [--remove-header-and-footer]
|
15
|
+
github-to-canvas --create-lesson COURSE
|
16
|
+
github-to-canvas --create-lesson COURSE [--save]
|
17
|
+
github-to-canvas --create-lesson COURSE [--branch BRANCH]
|
18
|
+
github-to-canvas --create-lesson COURSE [--branch BRANCH] [--name NAME]
|
19
|
+
github-to-canvas --create-lesson COURSE [--branch BRANCH] [--name NAME] [--type TYPE]
|
20
|
+
github-to-canvas --create-lesson COURSE [--fis-links]
|
21
|
+
github-to-canvas --create-lesson COURSE [--fis-links] [--remove-header-and-footer]
|
23
22
|
github-to-canvas --align
|
24
23
|
github-to-canvas --align [--branch BRANCH]
|
25
24
|
github-to-canvas --align [--branch BRANCH] [--fis-links]
|
@@ -31,19 +30,19 @@ OptionParser.new do |opts|
|
|
31
30
|
|
32
31
|
Example usage:
|
33
32
|
|
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
|
36
|
-
github-to-canvas --create 154 --name "Fetch Lab" --type assignment -> Creates an assignment 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
|
33
|
+
github-to-canvas --create-lesson 154 -> Creates a lesson in course 154, derives the name and type from the local repo
|
34
|
+
github-to-canvas --create-lesson 154 --name "Fetch Lab" -> Creates a lesson in course 154 with the provided name, derives the type from the local repo
|
35
|
+
github-to-canvas --create-lesson 154 --name "Fetch Lab" --type assignment -> Creates an assignment in course 154 with the provided name
|
36
|
+
github-to-canvas --create-lesson 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
|
38
37
|
github-to-canvas --align -> Patches existing lessons in Canvas based on the .canvas file
|
39
38
|
github-to-canvas --align --fis-links -> Patches existing lessons in Canvas based on the .canvas file, adds addition Flatiron School specific HTML
|
40
39
|
github-to-canvas --align --remove-header-and-footer -> Patches existing lessons in Canvas based on the .canvas file, removes top lesson header before converting to HTML
|
41
40
|
|
42
41
|
EOBANNER
|
43
42
|
|
44
|
-
opts.on("-cCOURSE", "--create COURSE",
|
43
|
+
opts.on("-cCOURSE", "--create-lesson COURSE",
|
45
44
|
"Creates a new canvas lesson, converting the local repository's README.md to HTML. Adds .canvas file to remote repository") do |course|
|
46
|
-
options[:
|
45
|
+
options[:create_lesson] = true
|
47
46
|
options[:course] = course
|
48
47
|
end
|
49
48
|
opts.on("-bBRANCH", "--branch BRANCH",
|
@@ -63,6 +62,14 @@ OptionParser.new do |opts|
|
|
63
62
|
options[:type] = "page"
|
64
63
|
end
|
65
64
|
end
|
65
|
+
opts.on("-fFILE", "--file FILE",
|
66
|
+
"Looks for and uses a markdown file in the currentt folder as source for conversion. Default file is README.md. Skips writing .canvas to repository") do |file|
|
67
|
+
options[:file_to_convert] = file
|
68
|
+
end
|
69
|
+
opts.on("-s", "--save-to-github",
|
70
|
+
"Creates a local .canvas file and attempts to commit and push it to the GitHub repository") do |s|
|
71
|
+
options[:save_to_github] = true
|
72
|
+
end
|
66
73
|
opts.on("-a", "--align",
|
67
74
|
"Updates a canvas lesson based on the local repository's README.md") do |a|
|
68
75
|
options[:align] = true
|
@@ -71,11 +78,7 @@ OptionParser.new do |opts|
|
|
71
78
|
"Displays current gem version") do |v|
|
72
79
|
options[:version] = true
|
73
80
|
end
|
74
|
-
opts.on("-
|
75
|
-
"Runs through creation without pushing to Canvas or GitHub") do |d|
|
76
|
-
options[:dry] = true
|
77
|
-
end
|
78
|
-
opts.on("-f", "--fis-links",
|
81
|
+
opts.on("-l", "--fis-links",
|
79
82
|
"Adds additional Flatiron School HTML after markdown conversion") do |f|
|
80
83
|
options[:fis] = true
|
81
84
|
end
|
@@ -90,6 +93,10 @@ if options[:version]
|
|
90
93
|
GithubToCanvas.new(mode: 'version', course: nil)
|
91
94
|
end
|
92
95
|
|
96
|
+
if !options[:file_to_convert]
|
97
|
+
options[:file_to_convert] = "README.md"
|
98
|
+
end
|
99
|
+
|
93
100
|
if !options[:type]
|
94
101
|
if Dir.glob("**/*/").empty?
|
95
102
|
options[:type] = "page"
|
@@ -106,14 +113,15 @@ if !options[:name]
|
|
106
113
|
options[:name] = File.basename(Dir.getwd)
|
107
114
|
end
|
108
115
|
|
109
|
-
if options[:
|
116
|
+
if options[:create_lesson]
|
110
117
|
GithubToCanvas.new(mode: "create",
|
111
118
|
course: options[:course],
|
112
119
|
filepath: Dir.pwd,
|
120
|
+
file_to_convert: options[:file_to_convert],
|
113
121
|
branch: options[:branch],
|
114
122
|
name: options[:name],
|
115
123
|
type: options[:type],
|
116
|
-
|
124
|
+
save_to_github: !!options[:save_to_github],
|
117
125
|
fis_links: !!options[:fis],
|
118
126
|
remove_header_and_footer: !!options[:remove_header_and_footer])
|
119
127
|
end
|
@@ -121,11 +129,12 @@ end
|
|
121
129
|
if options[:align]
|
122
130
|
GithubToCanvas.new(mode: "align",
|
123
131
|
course: nil,
|
124
|
-
filepath: Dir.pwd,
|
132
|
+
filepath: Dir.pwd,
|
133
|
+
file_to_convert: options[:file_to_convert],
|
125
134
|
branch: options[:branch],
|
126
135
|
name: options[:name],
|
127
136
|
type: options[:type],
|
128
|
-
|
137
|
+
save_to_github: !!options[:save_to_github],
|
129
138
|
fis_links: !!options[:fis],
|
130
139
|
remove_header_and_footer: !!options[:remove_header_and_footer])
|
131
140
|
end
|
data/lib/github-to-canvas.rb
CHANGED
@@ -12,10 +12,11 @@ class GithubToCanvas
|
|
12
12
|
def initialize(mode:,
|
13
13
|
course:,
|
14
14
|
filepath:Dir.pwd,
|
15
|
-
|
15
|
+
file_to_convert:'README.md',
|
16
|
+
branch:'master',
|
16
17
|
name:File.basename(Dir.getwd),
|
17
18
|
type:"page",
|
18
|
-
|
19
|
+
save_to_github:false,
|
19
20
|
fis_links:false,
|
20
21
|
remove_header_and_footer:false)
|
21
22
|
|
@@ -26,12 +27,12 @@ class GithubToCanvas
|
|
26
27
|
|
27
28
|
if mode == 'create'
|
28
29
|
puts "github-to-canvas will now create a Canvas lesson based on the current repo"
|
29
|
-
CreateCanvasLesson.new(course, filepath, branch, name, type,
|
30
|
+
CreateCanvasLesson.new(course, filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
|
30
31
|
end
|
31
32
|
|
32
33
|
if mode == 'align'
|
33
34
|
puts "github-to-canvas will now align any existing Canvas lessons based on the current repo. NOTE: .canvas file must be present"
|
34
|
-
UpdateCanvasLesson.new(filepath, branch, name, type,
|
35
|
+
UpdateCanvasLesson.new(filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
@@ -1,16 +1,15 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
|
3
2
|
class CanvasDotfile
|
4
3
|
|
5
4
|
def self.update_or_create(filepath, response, course, type)
|
6
5
|
if File.file?(".canvas")
|
7
|
-
if type == "assignment"
|
6
|
+
if type == "assignment" || type == "discussion"
|
8
7
|
canvas_data = self.update_assignment_data(response, course, type)
|
9
8
|
else
|
10
9
|
canvas_data = self.update_page_data(response, course, type)
|
11
10
|
end
|
12
11
|
else
|
13
|
-
if type == "assignment"
|
12
|
+
if type == "assignment" || type == "discussion"
|
14
13
|
canvas_data = self.create_assignment_data(response, course, type)
|
15
14
|
else
|
16
15
|
canvas_data = self.create_page_data(response, course, type)
|
@@ -1,19 +1,14 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'rest-client'
|
3
|
-
|
4
3
|
class CanvasInterface
|
5
4
|
|
6
|
-
def self.submit_to_canvas(course_id, type, name, readme
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
if ![200, 201].include? response.code
|
12
|
-
puts "Canvas push failed. #{response.code} status code returned "
|
13
|
-
abort
|
14
|
-
end
|
15
|
-
JSON.parse(response.body)
|
5
|
+
def self.submit_to_canvas(course_id, type, name, readme)
|
6
|
+
response = self.push_to_canvas(course_id, type, name, readme)
|
7
|
+
if ![200, 201].include? response.code
|
8
|
+
puts "Canvas push failed. #{response.code} status code returned "
|
9
|
+
abort
|
16
10
|
end
|
11
|
+
JSON.parse(response.body)
|
17
12
|
end
|
18
13
|
|
19
14
|
def self.push_to_canvas(course_id, type, name, new_readme)
|
@@ -29,11 +24,16 @@ class CanvasInterface
|
|
29
24
|
})
|
30
25
|
rescue
|
31
26
|
puts "Something went wrong while pushing lesson #{id} to course #{course_id}"
|
27
|
+
abort
|
32
28
|
end
|
33
29
|
end
|
34
30
|
|
35
31
|
def self.update_existing_lesson(course_id, id, type, name, new_readme, dry_run)
|
36
|
-
|
32
|
+
if type == "discussion"
|
33
|
+
url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}_topics/#{id}"
|
34
|
+
else
|
35
|
+
url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}s/#{id}"
|
36
|
+
end
|
37
37
|
payload = self.build_payload(type, name, new_readme)
|
38
38
|
begin
|
39
39
|
RestClient.put(url, payload, headers={
|
@@ -41,6 +41,7 @@ class CanvasInterface
|
|
41
41
|
})
|
42
42
|
rescue
|
43
43
|
puts "Something went wrong while pushing lesson #{id} to course #{course_id}"
|
44
|
+
# abort
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
@@ -1,29 +1,31 @@
|
|
1
1
|
class CreateCanvasLesson
|
2
2
|
|
3
|
-
def initialize(course, filepath, branch, name, type,
|
3
|
+
def initialize(course, filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
|
4
4
|
name = name.split(/[- _]/).map(&:capitalize).join(' ')
|
5
|
-
|
6
|
-
if !
|
7
|
-
puts
|
5
|
+
markdown = File.read("#{filepath}/#{file_to_convert}")
|
6
|
+
if !markdown
|
7
|
+
puts "#{file_to_convert} not found in current directory. Exiting..."
|
8
8
|
abort
|
9
9
|
end
|
10
|
-
create_canvas_lesson(
|
10
|
+
create_canvas_lesson(markdown, course, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
|
11
11
|
end
|
12
12
|
|
13
|
-
def create_canvas_lesson(
|
13
|
+
def create_canvas_lesson(markdown, course, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
|
14
14
|
GithubInterface.get_updated_repo(filepath, branch)
|
15
|
-
|
15
|
+
new_html = RepositoryConverter.convert(filepath, markdown, branch, remove_header_and_footer)
|
16
16
|
if fis_links
|
17
|
-
|
17
|
+
new_html = RepositoryConverter.add_fis_links(filepath, new_html)
|
18
18
|
end
|
19
|
-
response = CanvasInterface.submit_to_canvas(course, type, name,
|
20
|
-
if
|
21
|
-
puts '
|
22
|
-
else
|
19
|
+
response = CanvasInterface.submit_to_canvas(course, type, name, new_html)
|
20
|
+
if save_to_github
|
21
|
+
puts 'Creating .canvas file'
|
23
22
|
CanvasDotfile.update_or_create(filepath, response, course, type)
|
23
|
+
puts 'Commiting .canvas file'
|
24
24
|
CanvasDotfile.commit_canvas_dotfile(filepath)
|
25
|
+
puts 'Pushing .canvas file'
|
25
26
|
GithubInterface.git_push(filepath, branch)
|
26
27
|
end
|
28
|
+
puts "Canvas lesson created. Lesson available at #{response['html_url']}."
|
27
29
|
end
|
28
30
|
|
29
31
|
end
|
@@ -1,24 +1,25 @@
|
|
1
1
|
class UpdateCanvasLesson
|
2
2
|
|
3
|
-
def initialize(filepath, branch, name, type,
|
3
|
+
def initialize(filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
|
4
4
|
name = name.split(/[- _]/).map(&:capitalize).join(' ')
|
5
|
-
|
6
|
-
if !
|
7
|
-
puts
|
5
|
+
markdown = File.read("#{filepath}/#{file_to_convert}")
|
6
|
+
if !markdown
|
7
|
+
puts "#{file_to_convert} not found in current directory. Exiting..."
|
8
8
|
abort
|
9
9
|
end
|
10
|
-
update_canvas_lesson(
|
10
|
+
update_canvas_lesson(markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
|
11
11
|
end
|
12
12
|
|
13
|
-
def update_canvas_lesson(
|
13
|
+
def update_canvas_lesson(markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
|
14
14
|
GithubInterface.get_updated_repo(filepath, branch)
|
15
|
-
|
15
|
+
new_html = RepositoryConverter.convert(filepath, markdown, branch, remove_header_and_footer)
|
16
16
|
if fis_links
|
17
|
-
|
17
|
+
new_html = RepositoryConverter.add_fis_links(filepath, new_html) # adds Flatiron School specific header and footer
|
18
18
|
end
|
19
19
|
canvas_data = CanvasDotfile.read_canvas_data
|
20
20
|
canvas_data[:lessons].each { |lesson|
|
21
|
-
CanvasInterface.update_existing_lesson(lesson[:course_id], lesson[:id], type, name,
|
21
|
+
response = CanvasInterface.update_existing_lesson(lesson[:course_id], lesson[:id], lesson[:type], name, new_html, save_to_github)
|
22
|
+
puts "Canvas lesson created. Lesson available at #{response['html_url']}."
|
22
23
|
}
|
23
24
|
end
|
24
25
|
|