github-to-canvas 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +86 -75
- data/bin/github-to-canvas +30 -6
- data/lib/github-to-canvas.rb +22 -3
- data/lib/github-to-canvas/canvas_interface.rb +54 -5
- data/lib/github-to-canvas/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5628681c8cda313989c521770b0b7f2a20e9b7a0aa0f661446d25d1040eca8d
|
4
|
+
data.tar.gz: da78038dd5492dbb897c9fb6d65e05c76f02e7e57df952630c859d9b446d6c79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abc12344a24c0c7d67980dc4911462e7c7eb3aba0c31e18b42e5f95fda97fef7b60a994c4ce59fc6da3d6fb7db044fc47ae443979e06455a82906e4ae863f4cd
|
7
|
+
data.tar.gz: 467e1d799b929fccf52cb155d27411050232c30b704fde8d216516c1bc7891d69c6617252cfdd8782ceb35a10fd05b2d5efdf5dd6754bfb097f22ee740876f36
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ The `github-to-canvas` gem is designed to aid in integrating GitHub and the
|
|
6
6
|
Canvas LMS. This gem takes a GitHub repository's `README.md` file, converts it
|
7
7
|
to HTML, and pushes it to Canvas using the Canvas API. This gem can also update
|
8
8
|
existing Canvas lessons, allowing continuous alignment of content between GitHub
|
9
|
-
and Canvas
|
9
|
+
and Canvas.
|
10
10
|
|
11
11
|
This gem is built for use internally at [Flatiron School][], so some features may be
|
12
12
|
specific to Flatiron School branding and needs. Access to the
|
@@ -63,44 +63,21 @@ are present by running `ENV` and finding them in the output list.
|
|
63
63
|
|
64
64
|
## Common Uses
|
65
65
|
|
66
|
-
|
66
|
+
The GitHub to Canvas gem can be used for the following:
|
67
67
|
|
68
|
-
|
68
|
+
- [Create a Canvas Lesson from a Local Repository](#create)
|
69
|
+
- [Create a Canvas Lesson from a Remote Repository](#createremote)
|
70
|
+
- [Read a Remote Repository as HTML](#read)
|
71
|
+
- [Update a Canvas Lesson from a Local Repository](#update)
|
72
|
+
- [Update a Canvas Lesson from a Remote Repository](#updateremote)
|
73
|
+
- [Retrieve Canvas Course Information as YAML Markdown](#query)
|
74
|
+
- [Map GitHub Repositories to a Canvas Course YAML file](#map)
|
75
|
+
- [Create New Canvas Course from a YAML file](#buildcourse)
|
76
|
+
- [Update Lessons in an Existing Course from a YAML file](#updatecourse)
|
69
77
|
|
70
|
-
|
71
|
-
lesson, converting the local repository's README.md to HTML. Adds `.canvas`
|
72
|
-
file to remote repository
|
73
|
-
- `--align`, `-a`: Updates a canvas lesson based on the local repository's
|
74
|
-
README.md. If no other options are used, `--align` will look for a `.canvas`
|
75
|
-
file to know what to lesson to update
|
76
|
-
- `--course`: Provide a specific course ID. When used with `--id`, this can
|
77
|
-
override the default behavior for `--align`, allowing you to update any
|
78
|
-
existing lesson and ignore the `.canvas` file if present.
|
79
|
-
- `--id`: Provide a specific lesson ID. This can be found in the URL of the
|
80
|
-
specific lesson. For Pages, used the slugified lesson title.
|
81
|
-
- `--type`: Sets the type of Canvas lesson to be created (page, assignment or
|
82
|
-
discussion). If no type, type decided based on repository structure.
|
83
|
-
- `--name`: Can be used to override default naming behavior. By default, Canvas
|
84
|
-
lesson names are determined by the first top-level (`#`) header in the
|
85
|
-
repository's markdown file.
|
86
|
-
- `--fis-links`, `-l`: Adds additional Flatiron School HTML header after
|
87
|
-
markdown conversion, including links back to the GitHub repo and it's issue
|
88
|
-
form.
|
89
|
-
- `--forkable`: Adds a **Fork** button to the Flatiron School HTML header. For
|
90
|
-
use with custom Canvas JS to enable Canvas assignment forking workflow for
|
91
|
-
Flatiron School students.
|
92
|
-
- `--remove-header-and-footer`, `-r`: Removes top lesson header and any Flatiron
|
93
|
-
School specific footer links before converting to HTML. Removing top lesson
|
94
|
-
header prevent duplicate titles while viewing in Canvas.
|
95
|
-
- `--create-from-github`: Requires a GitHub repository URL. Also requires
|
96
|
-
`--course` and `--type`. Creates a Canvas lesson, reading from the remote repo
|
97
|
-
instead of a local repository. Repository must be public.
|
98
|
-
- `--align-from-github`: Requires a GitHub repo URL, `--course`, `--id`, and
|
99
|
-
`--type`. Updates a Canvas lesson from a remote repository.
|
100
|
-
- `--read-from-github`: Requires a GitHub repo URL. Reads a remote repository
|
101
|
-
and converts its contents to HTML, but does not push to Canvas.
|
78
|
+
### Creating and Updating Canvas Lessons
|
102
79
|
|
103
|
-
#### Create a Canvas Lesson from a Local Repository
|
80
|
+
#### Create a Canvas Lesson from a Local Repository <a name="create"></a>
|
104
81
|
|
105
82
|
Navigate into a repository folder cloned down to your local machine and run:
|
106
83
|
|
@@ -114,16 +91,15 @@ branded footers. It will also add an HTML header for Canvas that includes links
|
|
114
91
|
back to the repository.
|
115
92
|
|
116
93
|
If the lesson type is an assignment, a Fork button will also be added to the
|
117
|
-
HTML header. Because the command didn't specify, the type of lesson is
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
ignored.
|
94
|
+
HTML header. Because the command didn't specify, the type of lesson is determined
|
95
|
+
based on the local repo structure - if it has sub-folders, the lesson will become
|
96
|
+
an assignment; if there are no sub-folders, the lesson will become a page. If the
|
97
|
+
lesson type is a page, the `--forkable` option will be ignored.
|
122
98
|
|
123
99
|
Creating a lesson this way will also produce a `.canvas` file. This file
|
124
100
|
contains info about the Canvas lesson that was created.
|
125
101
|
|
126
|
-
#### Create a Canvas Lesson from a Remote Repository
|
102
|
+
#### Create a Canvas Lesson from a Remote Repository <a name="createremote"></a>
|
127
103
|
|
128
104
|
To create from a remote repo, run the following command:
|
129
105
|
|
@@ -139,7 +115,7 @@ lesson the same way as before.
|
|
139
115
|
|
140
116
|
The repository must be public in order to read the markdown file.
|
141
117
|
|
142
|
-
#### Read a Remote Repository as HTML
|
118
|
+
#### Read a Remote Repository as HTML <a name="read"></a>
|
143
119
|
|
144
120
|
To read the contents of a remote repo:
|
145
121
|
|
@@ -150,11 +126,11 @@ github-to-canvas --read-from-github <URL>
|
|
150
126
|
This will produce an HTML conversion of the repository's markdwon. This HTML can
|
151
127
|
be directly pasted into Canvas' HTML editor if a manual process is needed.
|
152
128
|
|
153
|
-
#### Update a Canvas Lesson from a Local Repository
|
129
|
+
#### Update a Canvas Lesson from a Local Repository <a name="update"></a>
|
154
130
|
|
155
131
|
If you previously created a Canvas lesson from a local repository, you should
|
156
132
|
have a `.canvas` file present in the repo. If that file is present, you can run
|
157
|
-
the following command to
|
133
|
+
the following command to update the listed Canvas lesson automatically:
|
158
134
|
|
159
135
|
```sh
|
160
136
|
github-to-canvas -a -lr --forkable
|
@@ -169,7 +145,7 @@ github-to-canvas -a --course <CANVAS_COURSE_ID> --id <CANVAS_LESSON_ID> -lr --fo
|
|
169
145
|
|
170
146
|
Canvas course and lesson IDs can be found in the URL.
|
171
147
|
|
172
|
-
#### Update a Canvas Lesson from a Remote Repository
|
148
|
+
#### Update a Canvas Lesson from a Remote Repository <a name="updateremote"></a>
|
173
149
|
|
174
150
|
You can update an existing Canvas course using a remote GitHub repository like so:
|
175
151
|
|
@@ -182,7 +158,7 @@ using the info provided. Type must match the existing lesson type.
|
|
182
158
|
|
183
159
|
### Course Creation
|
184
160
|
|
185
|
-
This gem
|
161
|
+
This gem can create Canvas courses from scratch. These features
|
186
162
|
are still in development and may not work for all course designs. Quiz and
|
187
163
|
Discussion Topic lesson creation is still under development and will not work.
|
188
164
|
|
@@ -191,7 +167,7 @@ course, add in modules, and populate those modules with pages and assignments.
|
|
191
167
|
The required YAML file must follow a specific structure. Using the steps below,
|
192
168
|
this gem can create the necessary YAML markup from existing Canvas courses.
|
193
169
|
|
194
|
-
#### Retrieve Canvas Course Information as YAML
|
170
|
+
#### Retrieve Canvas Course Information as YAML Markdown <a name="query"></a>
|
195
171
|
|
196
172
|
To create YAML markup of an existing Canvas course, use the following:
|
197
173
|
|
@@ -243,7 +219,7 @@ The output will look similar to this:
|
|
243
219
|
|
244
220
|
The output YAML will not include associated GitHub repository information.
|
245
221
|
|
246
|
-
#### Map GitHub Repositories to a Canvas Course YAML
|
222
|
+
#### Map GitHub Repositories to a Canvas Course YAML file <a name="map"></a>
|
247
223
|
|
248
224
|
To associate repositories to an existing course YAML, the following command can be used:
|
249
225
|
|
@@ -264,7 +240,7 @@ github-to-canvas --map query_results.yml > course_structure.yml
|
|
264
240
|
The resulting YAML file will contain course information, the module and lesson
|
265
241
|
structure, and each lesson's associated GitHub repository.
|
266
242
|
|
267
|
-
#### Create New Canvas Course from YAML
|
243
|
+
#### Create New Canvas Course from a YAML file <a name="buildcourse"></a>
|
268
244
|
|
269
245
|
To create a Canvas course with this gem, you will need a correctly structured
|
270
246
|
YAML file with the course info, modules, lessons and associated lesson
|
@@ -288,18 +264,18 @@ This command will cause the following to happen:
|
|
288
264
|
- Create the second lesson and add it to the module...
|
289
265
|
- Repeate process until all modules and lessons are created
|
290
266
|
|
291
|
-
####
|
267
|
+
#### Update Lessons in an Existing Course from a YAML file <a name="updatecourse"></a>
|
292
268
|
|
293
|
-
|
294
|
-
|
295
|
-
|
269
|
+
The GitHub to Canvas gem can be used to update all lessons in a course
|
270
|
+
with a single command. To do this, you will need an up-to-date course YAML file with repositories
|
271
|
+
mapped to each lesson.
|
296
272
|
|
297
273
|
```sh
|
298
274
|
github-to-canvas --query <COURSE_ID> > query_results.yml
|
299
275
|
github-to-canvas --map query_results.yml > your_new_course.yml
|
300
276
|
```
|
301
277
|
|
302
|
-
|
278
|
+
Use the resulting file (in this example, `your_new_course.yml`) to update all lessons in
|
303
279
|
a course based on their GitHub repo:
|
304
280
|
|
305
281
|
```sh
|
@@ -314,9 +290,9 @@ associated repository.
|
|
314
290
|
### HTML Code Snippets Do Not Render
|
315
291
|
|
316
292
|
The Canvas API renders all HTML it receives. If your repository's markdown
|
317
|
-
includes HTML that is not meant to be rendered
|
318
|
-
|
319
|
-
|
293
|
+
includes HTML that is not meant to be rendered, the content will be rendered as
|
294
|
+
part of the page's HTML, resulting in unusual display errors in Canvas. Examples of
|
295
|
+
this would be lessons on HTML or JavaScript that include HTML code snippets.
|
320
296
|
|
321
297
|
To fix any rendering issues in Canvas, go to the Canvas WYSIWYG editor for the
|
322
298
|
afflicted lesson. Click the HTML editor option (`</>` button in the lower right) to
|
@@ -352,9 +328,17 @@ issues, please open a new issue with a markdown example to replicate the error.
|
|
352
328
|
|
353
329
|
### Markdown Formatting Issues Cause Errors in Canvas
|
354
330
|
|
355
|
-
|
356
|
-
|
357
|
-
|
331
|
+
An empty line should separate individual markdown headers, paragraphs and code snippets
|
332
|
+
in the markdown. Without these empty lines, the contents will be interpretted as one
|
333
|
+
continuous paragraph and ignore formatting.
|
334
|
+
|
335
|
+
### New Repos That Use a `main` Branch
|
336
|
+
|
337
|
+
If you are using a new GitHub repository that uses a `main` branch, you may not be able to
|
338
|
+
create or update from a remote repository. You can still create and update from a local
|
339
|
+
repository by using the `--branch` (`-b`) option and specifying `main` as the branch.
|
340
|
+
|
341
|
+
A fix is planned for this issue, but not implemented.
|
358
342
|
|
359
343
|
## Overview of GitHub to Canvas workflows
|
360
344
|
|
@@ -362,9 +346,8 @@ Using this gem, you can maintain Canvas courses in multiple ways - either by
|
|
362
346
|
creating and updating individual Canvas lessons or through the YAML file process.
|
363
347
|
|
364
348
|
At Flatiron School, we use the Canvas blueprint course feature. We use the
|
365
|
-
github-to-canvas gem to update the blueprint copy of lessons. These updates will
|
366
|
-
|
367
|
-
copies.
|
349
|
+
github-to-canvas gem to update the blueprint copy of lessons. These updates will appear
|
350
|
+
in future copies of the course or when synced down associated courses in Canvas.
|
368
351
|
|
369
352
|

|
370
353
|
|
@@ -375,18 +358,46 @@ If you are using github-to-canvas in this way, changes should always be made on
|
|
375
358
|
the repository, not on Canvas. Any changes made only on Canvas will get
|
376
359
|
overwritten if the lesson is updated using the gem.
|
377
360
|
|
378
|
-
##
|
379
|
-
|
380
|
-
### Specify Branch
|
381
|
-
|
382
|
-
When creating or aligning content locally, you can use `--branch` (`-b`) to
|
383
|
-
specify which branch you want to use. If you have a newer repository with a
|
384
|
-
`main` branch instead of `master`, use this option.
|
361
|
+
## Common Options
|
385
362
|
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
363
|
+
- `--create-lesson`, `-c`: Requires a Canvas course ID. Creates a new Canvas
|
364
|
+
lesson, converting the local repository's README.md to HTML. Adds `.canvas`
|
365
|
+
file to remote repository
|
366
|
+
- `--align`, `-a`: Updates a canvas lesson based on the local repository's
|
367
|
+
README.md. If no other options are used, `--align` will look for a `.canvas`
|
368
|
+
file to know what to lesson to update
|
369
|
+
- `--course`: Provide a specific course ID. When used with `--id`, this can
|
370
|
+
override the default behavior for `--align`, allowing you to update any
|
371
|
+
existing lesson and ignore the `.canvas` file if present.
|
372
|
+
- `--id`: Provide a specific lesson ID. This can be found in the URL of the
|
373
|
+
specific lesson. For Pages, used the slugified lesson title.
|
374
|
+
- `--type`: Sets the type of Canvas lesson to be created (page, assignment or
|
375
|
+
discussion). If no type, type decided based on repository structure.
|
376
|
+
- `--name`: Can be used to override default naming behavior. By default, Canvas
|
377
|
+
lesson names are determined by the first top-level (`#`) header in the
|
378
|
+
repository's markdown file.
|
379
|
+
- `--fis-links`, `-l`: Adds additional Flatiron School HTML header after
|
380
|
+
markdown conversion, including links back to the GitHub repo and it's issue
|
381
|
+
form.
|
382
|
+
- `--forkable`: Adds a **Fork** button to the Flatiron School HTML header. For
|
383
|
+
use with custom Canvas JS to enable Canvas assignment forking workflow for
|
384
|
+
Flatiron School students.
|
385
|
+
- `--remove-header-and-footer`, `-r`: Removes top lesson header and any Flatiron
|
386
|
+
School specific footer links before converting to HTML. Removing top lesson
|
387
|
+
header prevents duplicate titles while viewing in Canvas.
|
388
|
+
- `--create-from-github`: Requires a GitHub repository URL. Also requires
|
389
|
+
`--course` and `--type`. Creates a Canvas lesson, reading from the remote repo
|
390
|
+
instead of a local repository. Repository must be public.
|
391
|
+
- `--align-from-github`: Requires a GitHub repo URL, `--course`, `--id`, and
|
392
|
+
`--type`. Updates a Canvas lesson from a remote repository.
|
393
|
+
- `--read-from-github`: Requires a GitHub repo URL. Reads a remote repository
|
394
|
+
and converts its contents to HTML, but does not push to Canvas.
|
395
|
+
- `--branch`, `-b`: Can be used when creating or aligning with a local repo to
|
396
|
+
specify which branch to use. Use this if you have a new repository that uses a
|
397
|
+
`main` branch instead of `master`.
|
398
|
+
- `--save-to-github`, `-s`: If you are are creating or aligning content locally,
|
399
|
+
the `.canvas` file is not automatically committed to the repo. This option will
|
400
|
+
attempt to commit and push the `.canvas` file to the remote repository.
|
390
401
|
|
391
402
|
Run `github-to-canvas --help` for additional options not listed in this Readme.
|
392
403
|
|
data/bin/github-to-canvas
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'byebug'
|
1
2
|
#!/usr/bin/env ruby
|
2
3
|
require 'optparse'
|
3
4
|
require 'github-to-canvas'
|
@@ -75,12 +76,16 @@ OptionParser.new do |opts|
|
|
75
76
|
end
|
76
77
|
opts.on("-tTYPE", "--type TYPE",
|
77
78
|
"Sets the type Canvas lesson to be created (page or assignment). If no type, type decided based on repository structure") do |type|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
# byebug
|
80
|
+
puts type.downcase
|
81
|
+
options[:type] = type.downcase
|
82
|
+
abort if type == 'quiz' || type == 'discussion'
|
83
|
+
# if type == 'page' || type == 'assignment' || type == 'discussion' || type == 'quiz' || type == 'Page' || type == 'Assignment' || type == 'Discussion' || type == 'Quiz'
|
84
|
+
|
85
|
+
# else
|
86
|
+
# puts "Invalid type. Defaulting to page"
|
87
|
+
# options[:type] = "page"
|
88
|
+
# end
|
84
89
|
end
|
85
90
|
opts.on("-fFILE", "--file FILE",
|
86
91
|
"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|
|
@@ -130,6 +135,10 @@ OptionParser.new do |opts|
|
|
130
135
|
"REQUIRES -f or --file Associates canvas lessons with repositories. Use query to create required YAML file") do |file|
|
131
136
|
options[:map] = file
|
132
137
|
end
|
138
|
+
opts.on("--csv COURSE",
|
139
|
+
"Returns a course's lesson struction as CSV") do |course|
|
140
|
+
options[:csv] = course
|
141
|
+
end
|
133
142
|
opts.on("--read-from-canvas CANVAS_URL",
|
134
143
|
"Retrieves an existing Canvas lesson using the provided URL") do |url|
|
135
144
|
options[:read_from_canvas] = url
|
@@ -162,6 +171,10 @@ OptionParser.new do |opts|
|
|
162
171
|
"Updates all lessons in a course using remote repos in provided YAML file") do |file|
|
163
172
|
options[:update_course_lessons] = file
|
164
173
|
end
|
174
|
+
opts.on("--clone-from-yaml YAML_FILE",
|
175
|
+
"Iterates over provided course YAML file and clones repos locally") do |file|
|
176
|
+
options[:clone_from_yaml] = file
|
177
|
+
end
|
165
178
|
|
166
179
|
end.parse!
|
167
180
|
|
@@ -202,6 +215,7 @@ if options[:align_from_github]
|
|
202
215
|
course_id: options[:course_id],
|
203
216
|
type: options[:type],
|
204
217
|
id: options[:id],
|
218
|
+
name: options[:name],
|
205
219
|
remove_header_and_footer: !!options[:remove_header_and_footer],
|
206
220
|
forkable: !!options[:forkable],
|
207
221
|
fis_links: !!options[:fis])
|
@@ -221,6 +235,11 @@ if options[:map]
|
|
221
235
|
abort
|
222
236
|
end
|
223
237
|
|
238
|
+
if options[:csv]
|
239
|
+
GithubToCanvas.new(mode: 'csv', file_to_convert: options[:csv])
|
240
|
+
abort
|
241
|
+
end
|
242
|
+
|
224
243
|
if options[:build_course]
|
225
244
|
GithubToCanvas.new(mode: 'build_course',
|
226
245
|
file_to_convert: options[:build_course],
|
@@ -253,6 +272,11 @@ if options[:update_course_lessons]
|
|
253
272
|
abort
|
254
273
|
end
|
255
274
|
|
275
|
+
if options[:clone_from_yaml]
|
276
|
+
GithubToCanvas.new(mode: 'clone_course',
|
277
|
+
file_to_convert: options[:clone_from_yaml])
|
278
|
+
abort
|
279
|
+
end
|
256
280
|
|
257
281
|
if !options[:type]
|
258
282
|
if Dir.glob("**/*/").empty?
|
data/lib/github-to-canvas.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'byebug'
|
1
2
|
require_relative './github-to-canvas/create_canvas_lesson'
|
2
3
|
require_relative './github-to-canvas/update_canvas_lesson'
|
3
4
|
require_relative './github-to-canvas/canvas_dotfile'
|
@@ -21,6 +22,8 @@ class GithubToCanvas
|
|
21
22
|
CanvasInterface.get_course_info(options[:course_id], options[:id])
|
22
23
|
when 'map'
|
23
24
|
CanvasInterface.map_course_info(options[:file_to_convert])
|
25
|
+
when 'csv'
|
26
|
+
CanvasInterface.csv(options[:file_to_convert])
|
24
27
|
when 'canvas_read'
|
25
28
|
puts CanvasInterface.read_lesson(options[:filepath])
|
26
29
|
when 'github_read'
|
@@ -49,7 +52,7 @@ class GithubToCanvas
|
|
49
52
|
puts "Canvas lesson created. Lesson available at #{response['html_url']}"
|
50
53
|
when 'github_align'
|
51
54
|
html = RepositoryConverter.remote_file_conversion(options)
|
52
|
-
name = RepositoryInterface.get_name(options[:filepath], html)
|
55
|
+
name = options[:name] ? options[:name] : RepositoryInterface.get_name(options[:filepath], html)
|
53
56
|
html = RepositoryConverter.adjust_converted_html(options, html)
|
54
57
|
response = CanvasInterface.update_existing_lesson(options, name, html)
|
55
58
|
puts "Canvas lesson updated. Lesson available at #{response['html_url']}"
|
@@ -69,10 +72,8 @@ class GithubToCanvas
|
|
69
72
|
options[:course_id] = created_course_info["id"]
|
70
73
|
options[:filepath] = lesson["repository"]
|
71
74
|
|
72
|
-
|
73
75
|
html = RepositoryConverter.remote_file_conversion(options)
|
74
76
|
# Add each lesson to it's module
|
75
|
-
|
76
77
|
html = RepositoryConverter.adjust_converted_html(options, html)
|
77
78
|
created_lesson_info = CanvasInterface.create_lesson(options, lesson["title"], html)
|
78
79
|
lesson = lesson.merge(created_lesson_info)
|
@@ -133,6 +134,24 @@ class GithubToCanvas
|
|
133
134
|
sleep(1)
|
134
135
|
}
|
135
136
|
}
|
137
|
+
when 'clone_course'
|
138
|
+
course_yaml = YAML.load(File.read(options[:file_to_convert]))
|
139
|
+
new_dir = "#{course_yaml[:name].downcase.gsub(' ','-')}"
|
140
|
+
cmd = "mkdir #{new_dir}"
|
141
|
+
`#{cmd}`
|
142
|
+
course_yaml[:modules].each { |module_info|
|
143
|
+
puts "Cloning #{module_info[:name]}"
|
144
|
+
module_info[:lessons].each { |lesson|
|
145
|
+
if lesson["repository"] == ""
|
146
|
+
puts "No repository found for #{lesson['title']}"
|
147
|
+
next
|
148
|
+
else
|
149
|
+
cmd = "git clone #{lesson['repository']}"
|
150
|
+
puts cmd
|
151
|
+
GithubInterface.cd_into_and(new_dir, cmd)
|
152
|
+
end
|
153
|
+
}
|
154
|
+
}
|
136
155
|
else
|
137
156
|
puts VERSION
|
138
157
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'byebug'
|
1
2
|
require 'json'
|
2
3
|
require 'rest-client'
|
3
4
|
require 'yaml'
|
@@ -59,6 +60,7 @@ class CanvasInterface
|
|
59
60
|
'module_item[title]' => lesson_info["title"],
|
60
61
|
'module_item[type]' => lesson_info["type"],
|
61
62
|
'module_item[indent]' => 0,
|
63
|
+
'module_item[page_url]' => lesson_info["id"],
|
62
64
|
'module_item[completion_requirement][type]' => 'must_view'
|
63
65
|
}
|
64
66
|
elsif lesson_info["type"] == "Quiz"
|
@@ -69,14 +71,16 @@ class CanvasInterface
|
|
69
71
|
'module_item[title]' => lesson_info["title"],
|
70
72
|
'module_item[type]' => lesson_info["type"],
|
71
73
|
'module_item[indent]' => 1,
|
74
|
+
'module_item[content_id]' => lesson_info["id"],
|
72
75
|
'module_item[completion_requirement][type]' => 'must_submit'
|
73
76
|
}
|
74
77
|
end
|
75
78
|
begin
|
79
|
+
byebug
|
76
80
|
response = RestClient.post(url, payload, self.headers)
|
77
81
|
rescue
|
78
|
-
puts "Something went wrong while
|
79
|
-
puts "Something went wrong while
|
82
|
+
puts "Something went wrong while adding lesson #{lesson_info["id"]} to module #{module_info["id"]} in course #{course_id}" if lesson_info["type"] == "Assignment"
|
83
|
+
puts "Something went wrong while adding lesson #{lesson_info["page_url"]} to module #{module_info["id"]} in course #{course_id}" if lesson_info["type"] == "Page"
|
80
84
|
abort
|
81
85
|
end
|
82
86
|
|
@@ -95,7 +99,7 @@ class CanvasInterface
|
|
95
99
|
|
96
100
|
begin
|
97
101
|
headers = self.headers
|
98
|
-
if options[:type] == 'page'
|
102
|
+
if options[:type] == 'page' || options[:type] == 'Page'
|
99
103
|
response = RestClient.get(url, headers)
|
100
104
|
lesson_info = JSON.parse(response)
|
101
105
|
url = url.sub(/[^\/]+$/, lesson_info["page_id"].to_s)
|
@@ -170,6 +174,7 @@ class CanvasInterface
|
|
170
174
|
[info, type]
|
171
175
|
end
|
172
176
|
|
177
|
+
|
173
178
|
def self.get_course_info(course, id)
|
174
179
|
if id
|
175
180
|
lesson_data = self.get_lesson_info(course, id)
|
@@ -290,8 +295,52 @@ class CanvasInterface
|
|
290
295
|
puts course_info.to_yaml
|
291
296
|
end
|
292
297
|
|
293
|
-
def self.
|
294
|
-
|
298
|
+
def self.csv(file_to_convert)
|
299
|
+
course_info = YAML.load(File.read("#{Dir.pwd}/#{file_to_convert}"))
|
300
|
+
course_info[:modules] = course_info[:modules].map do |mod|
|
301
|
+
mod[:lessons] = mod[:lessons].map do |lesson|
|
302
|
+
|
303
|
+
url = lesson["url"]
|
304
|
+
response = RestClient.get(url, headers={
|
305
|
+
"Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
|
306
|
+
})
|
307
|
+
begin
|
308
|
+
lesson_data = JSON.parse(response)
|
309
|
+
contents = lesson_data["body"] if lesson["type"] == "Page"
|
310
|
+
contents = lesson_data["message"] if lesson["type"] == "Discussion"
|
311
|
+
contents = lesson_data["description"] if lesson["type"] == "Assignment" || lesson["type"] == "Quiz"
|
312
|
+
if contents.nil?
|
313
|
+
repo = ""
|
314
|
+
else
|
315
|
+
if contents[/data-repo=\"(.*?)"/]
|
316
|
+
repo = contents[/data-repo=\"(.*?)"/]
|
317
|
+
repo = repo.slice(11..-2)
|
318
|
+
elsif contents[/class=\"fis-git-link\" href=\"(.*?)"/]
|
319
|
+
repo = contents[/class=\"fis-git-link\" href=\"(.*?)"/]
|
320
|
+
repo = repo.slice(27..-2)
|
321
|
+
else
|
322
|
+
repo = ""
|
323
|
+
end
|
324
|
+
end
|
325
|
+
rescue
|
326
|
+
puts 'Error while mapping course info.'
|
327
|
+
abort
|
328
|
+
end
|
329
|
+
|
330
|
+
if repo != nil && repo != ""
|
331
|
+
if repo.include?('https://github.com/learn-co-curriculum/')
|
332
|
+
lesson["repository"] = repo
|
333
|
+
else
|
334
|
+
lesson["repository"] = "https://github.com/learn-co-curriculum/" + repo
|
335
|
+
end
|
336
|
+
end
|
337
|
+
sleep(1)
|
338
|
+
lesson
|
339
|
+
end
|
340
|
+
mod
|
341
|
+
end
|
342
|
+
byebug
|
343
|
+
puts course_info.to_yaml
|
295
344
|
end
|
296
345
|
|
297
346
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-to-canvas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maxwellbenton
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
111
|
+
rubygems_version: 3.0.8
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: github-to-canvas is a tool for migrating and aligning GitHub content with
|