github-to-canvas 0.0.17 → 0.0.22

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: 4c34f751012912f2dab63047ccb3d988f7f2c072f72ef10fe197a11b65ef3ce4
4
- data.tar.gz: 8a8c5c2b21ff81708fb56d75154e1d286f2a6f4ec76f58b42b862b90dde26982
3
+ metadata.gz: 30ee9448d74c258ca7d0a142e4b2fa4bfa708b227014fd3ef9cd5daf483b0da7
4
+ data.tar.gz: 84d2710f793fcf93beea70c5693554920b14890c0260e7d20bb28dbf1d3723c3
5
5
  SHA512:
6
- metadata.gz: 39e7585eb2b1f01dd30dda410abaad6b6440c377d573535e1bec44e9950136c46e89016a4d62449ae6c466956bff7ec78097e62576165cbbec007041dce6f767
7
- data.tar.gz: 327074a131b23b3ec67b7f21fe782894674eee079009eb637af9758e0992d30eeaf0093d86a931280ce968da2e6194bcfcb7ded701c68c9b25cd8860f83845e2
6
+ metadata.gz: 75c3662d1354d1c5ed0e83ec625eed59010dc254ec9fa5663a060d7f32e58cf937ead936dabf8debd1e3f3f2d07f26747c17945b3a99fc3054244fea9be518b2
7
+ data.tar.gz: cbc3df60cb990b5c7fffd58b04a0a575c1ec2e4b513f68f7d080b724ee6da94726e14e4d405b77a38389ad1fe470b7c7b2fb03b8f40f00835bdbfebefe52c795
@@ -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
 
@@ -74,10 +84,12 @@ if options[:version]
74
84
  GithubToCanvas.new(mode: 'version', course: nil)
75
85
  end
76
86
 
77
- if Dir.glob("**/*/").empty?
78
- options[:type] = "page"
79
- else
80
- options[:type] = "assignment"
87
+ if !options[:type]
88
+ if Dir.glob("**/*/").empty?
89
+ options[:type] = "page"
90
+ else
91
+ options[:type] = "assignment"
92
+ end
81
93
  end
82
94
 
83
95
  if !options[:branch]
@@ -89,9 +101,9 @@ if !options[:name]
89
101
  end
90
102
 
91
103
  if options[:create]
92
- 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])
93
105
  end
94
106
 
95
107
  if options[:align]
96
- 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])
97
109
  end
@@ -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
- RestClient.post(url, payload, headers={
24
- "Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
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
- RestClient.put(url, payload, headers={
32
- "Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
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.cd_into_and(filepath, command)
10
- cmd = "cd #{filepath} && #{command}"
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
- branch = self.cd_into_and(filepath, "git checkout #{branch}")
17
- if branch.to_s.strip.empty?
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
@@ -1,5 +1,4 @@
1
1
  require 'redcarpet'
2
-
3
2
  class RepositoryConverter
4
3
 
5
4
  def self.convert(filepath, readme, branch)
@@ -16,6 +15,14 @@ class RepositoryConverter
16
15
  def self.set_raw_image_remote_url(filepath)
17
16
  remote = GithubInterface.git_remote(filepath)
18
17
  remote.gsub!("git@github.com:","https://raw.githubusercontent.com/")
18
+ remote.gsub!("https://github.com/","https://raw.githubusercontent.com/")
19
+ remote.gsub!(/.git$/,"")
20
+ remote.strip!
21
+ end
22
+
23
+ def self.get_repo_url(filepath)
24
+ remote = GithubInterface.git_remote(filepath)
25
+ remote.gsub!("git@github.com:","https://github.com/")
19
26
  remote.gsub!(/.git$/,"")
20
27
  remote.strip!
21
28
  end
@@ -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)
@@ -1,3 +1,3 @@
1
1
  class GithubToCanvas
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.22"
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.17
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton