github-to-canvas 0.0.40 → 0.0.45

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47468e628c6efba04bc04fc9f356e4b8f6866d1fe8bab6cfb5b4cfd7cf3a136e
4
- data.tar.gz: 6ea24930762e969677a535bf4e01e227e590eb9770d67819697fdd782ccfc389
3
+ metadata.gz: 2b28731821e3bad40e0d51ce6689f426f20a877a56467237f5707e269da1e57f
4
+ data.tar.gz: df5f3992733edf5ff876a7a80da8e88876462328a91e71f1f82821484f778249
5
5
  SHA512:
6
- metadata.gz: 73f226acaf498238218114b38587581dd7f9a2cd15a2f3f5058cb8ad4e2915319315c8d9f1d038ed48c635447e714df66f1ee0e06cb1a812ec3b7a8267d19931
7
- data.tar.gz: 1ae3ebf8b2cb9965bfbbb5a34647529d34fc3dc9e87a1e4ecab142c0e577c78dc4425ac4fa554e3a9cad55520c23421164b930316f023dadbc2dce777ad14e47
6
+ metadata.gz: a86f2918add3b43cbdb3df0854bba20610307fcb8f93cfb10ae4be6360a4fa10e13c3718b8391947264390cf2bc844e8cce8ef6b9f41b9b37a0cc546c5413442
7
+ data.tar.gz: 1824173a9ca13b42ddd793f0eb61cf8a2b2ceee9d7b94de2599734545d8e0e003d7c679515a6494bcf7fe85ecd33f4a1a3b47795277f0d31a67d87a615da7bf6
data/README.md CHANGED
@@ -2,19 +2,21 @@
2
2
 
3
3
  ## Introduction
4
4
 
5
- The `github-to-canvas` gem is designed to enable GitHub to Canvas LMS
6
- integration. This gem is designed to take a GitHub repository's `README.md`
7
- file, convert it to HTML, and push it to Canvas. The gem also updates the
8
- repository to include a `.canvas` file containing Canvas specific information.
5
+ The `github-to-canvas` gem is designed to aid in integrating GitHub and the
6
+ Canvas LMS. This gem takes a GitHub repository's `README.md` file, converts it
7
+ to HTML, and pushes it to Canvas using the Canvas API. The gem also has the ability
8
+ to updates a repository to include a `.canvas` file containing Canvas specific
9
+ information.
9
10
 
10
11
  With the `.canvas` file in place, this gem can be used to continuously align
11
12
  content between GitHub and Canvas using the GitHub repository as the single
12
13
  source of truth.
13
14
 
14
- This gem is built for use internally at [Flatiron School][]. Access to the
15
+ This gem is built for use internally at [Flatiron School][], so some features may be
16
+ specific to Flatiron School branding and needs. Access to the
15
17
  [Canvas LMS API][] and the ability to add pages and assignments to a Canvas
16
18
  course are required. Write access to the GitHub repository being converted is
17
- also required.
19
+ also required for committing `.canvas` files.
18
20
 
19
21
  ## Installation
20
22
 
@@ -27,15 +29,21 @@ also required.
27
29
  In order to access the Canvas API, you must first generate an API key. Go to
28
30
  your Canvas Account Settings and under **Approved Integrations**, create a
29
31
  **New Access Token**. You will need to store this API key as an `ENV` variable
30
- called `CANVAS_API_KEY`. Use the following command to add your new key to
31
- `~/.zshrc`:
32
+ called `CANVAS_API_KEY`.
33
+
34
+ If you are using Zsh, the following command will add your new key to the top of `~/.zshrc`:
35
+
36
+ ```sh
37
+ echo "$(export 'CANVAS_API_KEY=your-new-API-key-here' | cat - ~/.zshrc)" > ~/.zshrc
38
+ ```
39
+
40
+ If you are using Bash, use this command instead:
32
41
 
33
42
  ```sh
34
- echo "$(export 'CANVAS_API_KEY=<your-new-API-key-here>' | cat - ~/.zshrc)" > ~/.zshrc
43
+ echo "$(export 'CANVAS_API_KEY=your-new-API-key-here' | cat - ~/.bash_profile)" > ~/.bash_profile
35
44
  ```
36
45
 
37
- > **Note:** The command above assumes you are using Zsh. Change the dotfile if
38
- > you are using something else like Bash.
46
+ > If you aren't sure which you use, run `echo $SHELL`
39
47
 
40
48
  ### Add Canvas API Base Path
41
49
 
@@ -47,9 +55,15 @@ as an `ENV` variable like the API key. **Do not add a `/` at the end after `/api
47
55
  echo "$(export 'CANVAS_API_PATH=<your-base-api-path>' | cat - ~/.zshrc)" > ~/.zshrc
48
56
  ```
49
57
 
50
- After both the API key and path are added to `~/.zshrc`, run `source ~/.zshrc`
58
+ Or for Bash:
59
+
60
+ ```sh
61
+ echo "$(export 'CANVAS_API_PATH=<your-base-api-path>' | cat - ~/.bash_profile)" > ~/.bash_profile
62
+ ```
63
+
64
+ After both the API key and path are added to `~/.zshrc`, run `source ~/.zshrc` (`source ~/.bash_profile` for Bash)
51
65
  to make them available in your current terminal. You can verify these variables
52
- are present by running `ENV`.
66
+ are present by running `ENV` and finding them in the output list.
53
67
 
54
68
  ## Usage
55
69
 
@@ -70,26 +84,23 @@ using `master` branch `README.md` and the name of the current folder. By
70
84
  default, if the repository contains folders, an **assignment** will be created.
71
85
  Otherwise, a **page** will be created.
72
86
 
73
- After a successful lesson creation, `github-to-canvas` will use the API response
74
- to build a `.canvas` YAML file. This file contains the course id, the newly
75
- created page id, and the Canvas URL to the lesson for future reference. With the
76
- newly created `.canvas` file, `github-to-canvas` will attempt to commit and push the
77
- file up to the remote GitHub repository.
87
+ ### Saving `.canvas` to GitHub
88
+
89
+ Using `--save-to-github` will create a `.canvas` YAML file in the local repo and attempt to commit
90
+ and push it to the remote repository. This file contains the course id, the newly
91
+ created page id, and the Canvas URL to the lesson for future reference.
78
92
 
79
93
  If you create multiple Canvas lessons from the same repository, each lesson's
80
94
  Canvas data will be stored in the `.canvas` file.
81
95
 
82
- > **Note:** If you don't have write access to the repository, the `.canvas` file
83
- > will still be created locally.
84
-
85
- ### Update an existing Canvas Lesson
96
+ ### Update an Existing Canvas Lesson
86
97
 
87
98
  To update an existing Canvas lesson using a local repository, **a `.canvas` file
88
99
  must be present in the repo**, as it contains the lesson information for the
89
100
  Canvas API.
90
101
 
91
102
  1. Clone down and/or change directory into the repository you'd like to update
92
- 2. Run `github-to-canvas --align <your-course-id>` from inside the local repo
103
+ 2. Run `github-to-canvas --align` from inside the local repo
93
104
 
94
105
  `github-to-canvas` will get the course id and page/assignment id from the
95
106
  `.canvas` file and update the associated Canvas lesson. If there are multiple
@@ -98,13 +109,20 @@ you have the same lesson in two courses created from one repository).
98
109
 
99
110
  ### Options
100
111
 
101
- You can override the default behaviors with the following arguments:
102
-
103
- * `--name NAME` uses the provided name instead of the repository's folder name
104
- * `--branch BRANCH` uses the provided git branch instead of `master`
105
- * `--type TYPE` will accept either `'page'` or `'assignment'` and create the
106
- appropriate Canvas lesson type instead of relying on the repository's
107
- directory structure
112
+ This gem provides to the following options:
113
+
114
+ * `-c, --create-lesson COURSE` - Creates a new Canvas lesson, converting the local repository's README.md to HTML. Adds .canvas file to remote repository
115
+ * `-a, --align` - Updates a canvas lesson based on the local repository's README.md
116
+ * `-n, --name NAME` - Sets the name of the new Canvas lesson to be created. If no name is given, repository folder name is used
117
+ * `-t, --type TYPE` - Sets the type of Canvas lesson to be created (page, assignment or discussion). If no type, type decided based on repository structure
118
+ * `-f, --file FILE` - Looks for and uses a markdown file in the currentt folder as source for conversion. Default file is README.md
119
+ * `-b, --branch BRANCH` - Sets the repository branch used for lesson creation
120
+ * `-s, --save-to-github` - Creates a local .canvas file and attempts to commit and push it to the GitHub repository
121
+ * `-l, --fis-links` - Adds additional Flatiron School HTML after markdown conversion
122
+ * `-r, --remove-header-and-footer` - Removes top lesson header and any Learn.co specific footer links before converting to HTML
123
+ * `-o, --only-content` - For align functionality only - updates the HTML content of a lesson without changing the name
124
+ * `-h, --help` - Outputs examples commands and all options
125
+
108
126
 
109
127
  ## Examples of Valid Images This Gem Can Convert
110
128
 
@@ -119,4 +137,4 @@ HTML:
119
137
  </p>
120
138
 
121
139
  [Canvas LMS API]: https://canvas.instructure.com/doc/api/index.html
122
- [Flatiron School]: https://flatironschool.com/
140
+ [Flatiron School]: https://flatironschool.com/
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require 'optparse'
4
3
  require 'github-to-canvas'
5
4
  options = {}
@@ -23,6 +22,7 @@ OptionParser.new do |opts|
23
22
  github-to-canvas --align [--branch BRANCH]
24
23
  github-to-canvas --align [--only-content]
25
24
  github-to-canvas --align [--branch BRANCH] [--fis-links]
25
+ github-to-canvas --info COURSE
26
26
  github-to-canvas --version
27
27
 
28
28
 
@@ -35,9 +35,10 @@ OptionParser.new do |opts|
35
35
  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
36
36
  github-to-canvas --create-lesson 154 --name "Fetch Lab" --type assignment -> Creates an assignment in course 154 with the provided name
37
37
  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
- github-to-canvas --align -> 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-and-footer -> Patches existing lessons in Canvas based on the .canvas file, removes top lesson header before converting to HTML
38
+ github-to-canvas --align -> 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-and-footer -> Patches existing lessons in Canvas based on the .canvas file, removes top lesson header before converting to HTML
41
+ github-to-canvas --info COURSE -> Displays a course's lesson and assignment names
41
42
 
42
43
  EOBANNER
43
44
 
@@ -87,10 +88,22 @@ OptionParser.new do |opts|
87
88
  "Removes top lesson header and any Learn.co specific footer links before converting to HTML") do |r|
88
89
  options[:remove_header_and_footer] = true
89
90
  end
91
+ opts.on("--course COURSE",
92
+ "For align functionality only - updates the HTML content of a lesson using the provided course ID. Use with --id.") do |course|
93
+ options[:course] = course
94
+ end
95
+ opts.on("--id ID",
96
+ "For align functionality only - updates the HTML content of a lesson using the provided assignment or page ID. Use with --course.") do |id|
97
+ options[:id] = id
98
+ end
90
99
  opts.on("-o", "--only-content",
91
100
  "For align functionality only - updates the HTML content of a lesson without changing the name") do |o|
92
101
  options[:only_content] = true
93
102
  end
103
+ opts.on("-q COURSE", "--query COURSE",
104
+ "Displays a course's lessons and assignments") do |course|
105
+ options[:query] = course
106
+ end
94
107
 
95
108
  end.parse!
96
109
 
@@ -98,6 +111,10 @@ if options[:version]
98
111
  GithubToCanvas.new(mode: 'version', course: nil)
99
112
  end
100
113
 
114
+ if options[:query]
115
+ GithubToCanvas.new(mode: 'query', course: options[:query], id: options[:id])
116
+ end
117
+
101
118
  if !options[:type]
102
119
  if Dir.glob("**/*/").empty?
103
120
  options[:type] = "page"
@@ -112,9 +129,23 @@ end
112
129
 
113
130
  if !options[:name]
114
131
  if options[:file_to_convert]
115
- options[:name] = options[:file_to_convert]
132
+ markdown = File.read("#{Dir.pwd}/#{options[:file_to_convert]}")
133
+ if markdown.match?(/^# .+?\n\n/)
134
+ options[:name] = markdown.match(/^# .+?\n\n/)[0].strip.gsub("# ","").gsub("#","")
135
+ elsif markdown.match?(/^# .+?\n/)
136
+ options[:name] = markdown.match(/^# .+?\n/)[0].strip.gsub("# ","").gsub("#","")
137
+ else
138
+ options[:name] = options[:file_to_convert]
139
+ end
116
140
  else
117
- options[:name] = File.basename(Dir.getwd)
141
+ markdown = File.read("#{Dir.pwd}/README.md")
142
+ if markdown.match?(/^# .+?\n\n/)
143
+ options[:name] = markdown.match(/^# .+?\n\n/)[0].strip.gsub("# ","").gsub("#","")
144
+ elsif markdown.match?(/^# .+?\n/)
145
+ options[:name] = markdown.match(/^# .+?\n/)[0].strip.gsub("# ","").gsub("#","")
146
+ else
147
+ options[:name] = File.basename(Dir.getwd)
148
+ end
118
149
  options[:file_to_convert] = "README.md"
119
150
  end
120
151
  end
@@ -139,7 +170,8 @@ end
139
170
 
140
171
  if options[:align]
141
172
  GithubToCanvas.new(mode: "align",
142
- course: nil,
173
+ course: options[:course],
174
+ id: options[:id],
143
175
  filepath: Dir.pwd,
144
176
  file_to_convert: options[:file_to_convert],
145
177
  branch: options[:branch],
@@ -10,7 +10,8 @@ require_relative './github-to-canvas/version'
10
10
  class GithubToCanvas
11
11
 
12
12
  def initialize(mode:,
13
- course:,
13
+ course:nil,
14
+ id:nil,
14
15
  filepath:Dir.pwd,
15
16
  file_to_convert:'README.md',
16
17
  branch:'master',
@@ -23,7 +24,10 @@ class GithubToCanvas
23
24
 
24
25
  if mode == 'version'
25
26
  puts VERSION
26
- return
27
+ end
28
+
29
+ if mode == 'query'
30
+ CanvasInterface.get_course_info(course, id)
27
31
  end
28
32
 
29
33
  if mode == 'create'
@@ -33,7 +37,7 @@ class GithubToCanvas
33
37
 
34
38
  if mode == 'align'
35
39
  puts "github-to-canvas will now align any existing Canvas lessons based on the current repo. NOTE: .canvas file must be present"
36
- UpdateCanvasLesson.new(filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content)
40
+ UpdateCanvasLesson.new(course, filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content, id)
37
41
  end
38
42
  end
39
43
 
@@ -1,8 +1,12 @@
1
1
  require 'yaml'
2
2
  class CanvasDotfile
3
3
 
4
+ def self.exists?
5
+ File.file?(".canvas")
6
+ end
7
+
4
8
  def self.update_or_create(filepath, response, course, type)
5
- if File.file?(".canvas")
9
+ if self.exists?
6
10
  if type == "assignment" || type == "discussion"
7
11
  canvas_data = self.update_assignment_data(response, course, type)
8
12
  else
@@ -22,11 +26,6 @@ class CanvasDotfile
22
26
  File.write("#{filepath}/.canvas", canvas_data.to_yaml)
23
27
  end
24
28
 
25
- def self.commit_canvas_dotfile(filepath)
26
- GithubInterface.git_add(filepath, '.canvas')
27
- GithubInterface.git_commit(filepath, 'AUTO: add .canvas file after migration')
28
- end
29
-
30
29
  def self.read_canvas_data
31
30
  if File.file?(".canvas")
32
31
  YAML.load(File.read(".canvas"))
@@ -2,6 +2,80 @@ require 'json'
2
2
  require 'rest-client'
3
3
  class CanvasInterface
4
4
 
5
+ def self.get_lesson_info(course, id)
6
+ page_url = "#{ENV['CANVAS_API_PATH']}/courses/#{course}/pages/#{id}"
7
+ assignment_url = "#{ENV['CANVAS_API_PATH']}/courses/#{course}/assignments/#{id}"
8
+ type = nil
9
+ info = ""
10
+ begin
11
+ page_response = RestClient.get(page_url, headers={
12
+ "Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
13
+ })
14
+ if ([200, 201].include? page_response.code)
15
+ info = JSON.parse(page_response.body)
16
+ puts "A Canvas page with the ID #{id} was found in course #{course}:"
17
+ type = "page"
18
+ end
19
+ rescue
20
+ end
21
+
22
+ begin
23
+ assignment_response = RestClient.get(assignment_url, headers={
24
+ "Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
25
+ })
26
+ if ([200, 201].include? assignment_response.code)
27
+ info = JSON.parse(assignment_response.body)
28
+ puts "A Canvas assignment with the ID #{id} was found in course #{course}:"
29
+ type = "assignment"
30
+ end
31
+ rescue
32
+ end
33
+ [info, type]
34
+ end
35
+
36
+ def self.get_course_info(course, id)
37
+ if id
38
+ info = self.get_lesson_info(course, id)
39
+ pp info[1]
40
+ pp info[0]
41
+ return
42
+ end
43
+
44
+ begin
45
+ results = []
46
+ index = 1
47
+
48
+ while !!index
49
+ url = "#{ENV['CANVAS_API_PATH']}/courses/#{course}/pages?order=asc&sort=title&page=#{index}&per_page=10"
50
+ index += 1
51
+ response = RestClient.get(url, headers={
52
+ "Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
53
+ })
54
+ pages = JSON.parse(response.body)
55
+ if ([200, 201].include? response.code) && (!pages.empty?)
56
+ results = results + pages
57
+ else
58
+ index = nil
59
+ end
60
+ end
61
+ puts ""
62
+ puts ""
63
+ puts "Info for Course #{course} from #{ENV['CANVAS_API_PATH']}"
64
+ puts ""
65
+ puts "## Pages ##"
66
+ puts "Title : Page ID"
67
+ puts ""
68
+
69
+ results.each {|result|
70
+ puts "#{result['title']} : #{result['page_id']}"
71
+ }
72
+
73
+ rescue
74
+ puts "Something went wrong while getting info about course #{course}"
75
+ abort
76
+ end
77
+ end
78
+
5
79
  def self.submit_to_canvas(course_id, type, name, readme)
6
80
  response = self.push_to_canvas(course_id, type, name, readme)
7
81
  if ![200, 201].include? response.code
@@ -41,7 +115,7 @@ class CanvasInterface
41
115
  })
42
116
  rescue
43
117
  puts "Something went wrong while pushing lesson #{id} to course #{course_id}"
44
- # abort
118
+ nil
45
119
  end
46
120
  end
47
121
 
@@ -1,7 +1,7 @@
1
1
  class CreateCanvasLesson
2
2
 
3
3
  def initialize(course, filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
4
- name = name.split(/[- _]/).map(&:capitalize).join(' ')
4
+ # name = name.split(/[- _]/).map(&:capitalize).join(' ')
5
5
  begin
6
6
  markdown = File.read("#{filepath}/#{file_to_convert}")
7
7
  rescue
@@ -18,15 +18,21 @@ class CreateCanvasLesson
18
18
  new_html = RepositoryConverter.add_fis_links(filepath, new_html)
19
19
  end
20
20
  response = CanvasInterface.submit_to_canvas(course, type, name, new_html)
21
+
22
+ puts 'Creating .canvas file'
23
+ CanvasDotfile.update_or_create(filepath, response, course, type)
24
+
25
+ puts "Canvas lesson created. Lesson available at #{response['html_url']}."
26
+
27
+ # If --save option is used, the .canvas file gets committed and pushed to the remote repo
21
28
  if save_to_github
22
- puts 'Creating .canvas file'
23
- CanvasDotfile.update_or_create(filepath, response, course, type)
29
+ puts 'Adding .canvas file'
30
+ GithubInterface.git_add(filepath, '.canvas')
24
31
  puts 'Commiting .canvas file'
25
- CanvasDotfile.commit_canvas_dotfile(filepath)
32
+ GithubInterface.git_commit(filepath, 'AUTO: add .canvas file after migration')
26
33
  puts 'Pushing .canvas file'
27
34
  GithubInterface.git_push(filepath, branch)
28
35
  end
29
- puts "Canvas lesson created. Lesson available at #{response['html_url']}."
30
36
  end
31
37
 
32
38
  end
@@ -11,7 +11,8 @@ class RepositoryConverter
11
11
  end
12
12
 
13
13
  def self.remove_header(readme)
14
- readme.gsub(/^# .+?\n\n/,"")
14
+ readme.gsub!(/^# .+?\n\n/,"")
15
+ readme.gsub(/^# .+?\n/,"")
15
16
  end
16
17
 
17
18
  def self.remove_footer(readme)
@@ -40,27 +41,27 @@ class RepositoryConverter
40
41
  end
41
42
 
42
43
  def self.adjust_local_markdown_images(readme, raw_remote_url, branch)
43
- readme.gsub!(/\!\[.+\]\(.+\)/) {|image|
44
- if !image.match('amazonaws.com') && !image.match('https://') && !image.match('youtube')
45
- image.gsub!(/\(.+\)/) { |path|
44
+ readme.gsub!(/\!\[.+\]\(.+\)/) {|image_markdown|
45
+ if !image_markdown.match?('amazonaws.com') && !image_markdown.match?('https://') && !image_markdown.match?('http://') && !image_markdown.match?('youtube')
46
+ image_markdown.gsub!(/\(.+\)/) { |path|
46
47
  path.delete_prefix!("(")
47
48
  path.delete_suffix!(")")
48
49
  "(" + raw_remote_url + "/#{branch}/" + path + ")"
49
50
  }
50
51
  end
51
- image
52
+ image_markdown
52
53
  }
53
54
  end
54
55
 
55
56
  def self.adjust_local_html_images(readme, raw_remote_url)
56
- readme.gsub!(/src=\"[\s\S]*?" /) { |img|
57
- if !img.match('amazonaws.com') && !img.match('https://') && !img.match('youtube')
58
- img.gsub!(/\"/, "")
59
- img.gsub!(/src=/, '')
60
- img.strip!
61
- 'src="' + raw_remote_url + '/master/' + img + '"'
57
+ readme.gsub!(/src=\"[\s\S]*?"/) { |image_source|
58
+ if !image_source.match?('amazonaws.com') && !image_source.match?('https://') && !image_source.match?('http://') && !image_source.match?('youtube')
59
+ image_source.gsub!(/\"/, "")
60
+ image_source.gsub!(/src=/, '')
61
+ image_source.strip!
62
+ 'src="' + raw_remote_url + '/master/' + image_source + '"'
62
63
  else
63
- img
64
+ image_source
64
65
  end
65
66
  }
66
67
  end
@@ -1,29 +1,57 @@
1
1
  class UpdateCanvasLesson
2
2
 
3
- def initialize(filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content)
4
- name = name.split(/[- _]/).map(&:capitalize).join(' ')
3
+ def initialize(course, filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content, id)
4
+ # name = name.split(/[- _]/).map(&:capitalize).join(' ')
5
5
  begin
6
6
  markdown = File.read("#{filepath}/#{file_to_convert}")
7
7
  rescue
8
8
  puts "#{file_to_convert} not found in current directory. Exiting..."
9
9
  abort
10
10
  end
11
- update_canvas_lesson(markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content)
11
+ update_canvas_lesson(course, markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content, id)
12
12
  end
13
13
 
14
- def update_canvas_lesson(markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content)
14
+ def update_canvas_lesson(course, markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content, id)
15
+ # Pulls any updates that exist on GitHub
15
16
  GithubInterface.get_updated_repo(filepath, branch)
17
+
18
+ # Converts markdown to HTML
19
+ # Default is README.md. --file <FILENAME> can be used to override default.
16
20
  new_html = RepositoryConverter.convert(filepath, markdown, branch, remove_header_and_footer)
21
+
22
+ # adds Flatiron School specific header and footer
17
23
  if fis_links
18
- new_html = RepositoryConverter.add_fis_links(filepath, new_html) # adds Flatiron School specific header and footer
24
+ new_html = RepositoryConverter.add_fis_links(filepath, new_html)
19
25
  end
20
- canvas_data = CanvasDotfile.read_canvas_data
21
- canvas_data[:lessons].each { |lesson|
22
- response = CanvasInterface.update_existing_lesson(lesson[:course_id], lesson[:id], lesson[:type], name, new_html, only_update_content)
23
- # puts "Canvas lesson created. Lesson available at #{response['html_url']}."
24
- }
25
- end
26
26
 
27
+ # Read the local .canvas file if --id <ID> is not used. Otherwise, use provided ID (--course <COURSE> also required)
28
+ if !id
29
+ canvas_data = CanvasDotfile.read_canvas_data
30
+ canvas_data[:lessons] = canvas_data[:lessons].map { |lesson|
31
+ response = CanvasInterface.update_existing_lesson(lesson[:course_id], lesson[:id], lesson[:type], name, new_html, only_update_content)
32
+ }
33
+ else
34
+ # If an ID (and course) are provided, they are used instead of the .canvas file
35
+ # Gets the current lesson's type (page or assignment)
36
+ info = CanvasInterface.get_lesson_info(course, id)
37
+
38
+ # Implements update on Canvas
39
+ response = JSON.parse(CanvasInterface.update_existing_lesson(course, id, info[1], name, new_html, only_update_content))
40
+
41
+ # Updates or creates a local .canvas file
42
+ CanvasDotfile.update_or_create(filepath, response, course, info[1])
43
+ end
44
+ # If --save option is used, the .canvas file gets committed and pushed to the remote repo
45
+ if save_to_github
46
+ puts 'Adding .canvas file'
47
+ GithubInterface.git_add(filepath, '.canvas')
48
+ puts 'Commiting .canvas file'
49
+ GithubInterface.git_commit(filepath, 'AUTO: add .canvas file after migration')
50
+ puts 'Pushing .canvas file'
51
+ GithubInterface.git_push(filepath, branch)
52
+ end
53
+
54
+ end
27
55
 
28
56
 
29
57
  end
@@ -1,3 +1,3 @@
1
1
  class GithubToCanvas
2
- VERSION = "0.0.40"
2
+ VERSION = "0.0.45"
3
3
  end
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.0.40
4
+ version: 0.0.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton