til-rb 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/til/core.rb +18 -14
  3. data/lib/til/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36329998af769fde62b800136de45304100925992f85d14463a127070da4b66d
4
- data.tar.gz: e0283b08a1145176a3e6b7ea6e77dc65f4030f86571d7db3f6b475a3085213fa
3
+ metadata.gz: 7663677e1c231cfb2bbba240e889b85ac2ae1c22519b0c365fa225e91ed876f9
4
+ data.tar.gz: 5404592be317f806bec787e4f21a444ddbb22e2fe680b1278b93ad8c0b3bff72
5
5
  SHA512:
6
- metadata.gz: '092def75bd54793b9318dc91a0b58bf3a6b09a488100daa0320bf97882f6fa94c6b84686aaf54c12e5bf51b662cc322b41de9a0a62c7e2fd2bd66732d3e80780'
7
- data.tar.gz: 3d241da839314e320055bf5c2e717017f57deafdf2a9f3463a8174ccd4a846df3afa68c9f2601669ab5b54cd8aa034c0d864a68dff6d0a7e0136c0d48d199953
6
+ metadata.gz: 1b98afb9724d5818dc13d5dc0d59cc3b1ceeed17e6b111f09d00159eb2dc943b4649c59009bb815a86c1fb82e833eff16d00630d2abd35a101ed815da9b736a4
7
+ data.tar.gz: 7c5ccdb8864eefe7b7242a066b7d517cfe966e52fa610d95f85f7dfb546b7f97c2575d0eb7e75cde810d3ef1d7e3948def5f1bf370d9cee741d833995a28d63a
@@ -28,7 +28,7 @@ module Til
28
28
  @env = env
29
29
  @stderr = stderr
30
30
  @github_client = github_client
31
- @repo_name = 'pjambet/til'
31
+ @repo_name = nil
32
32
  @new_category = false
33
33
  end
34
34
 
@@ -62,13 +62,13 @@ module Til
62
62
  raise 'The GH_TOKEN (with the public_repo or repo scope) environment variable is required'
63
63
  end
64
64
 
65
- if (@env['VISUAL'].nil? || @env['VISUAL'] == '') && (@env['EDITOR'].nil? || @env['EDITOR'] == '')
66
- raise 'The VISUAL or EDITOR environment variables are required'
65
+ if @env['GH_REPO'].nil? || @env['GH_REPO'] == ''
66
+ raise 'The GH_REPO environment variable is required'
67
67
  end
68
68
  end
69
69
 
70
70
  def fetch_existing_categories
71
- existing_categories = github_client.contents(@repo_name, path: '').filter do |c|
71
+ existing_categories = github_client.contents(repo_name, path: '').filter do |c|
72
72
  c['type'] == 'dir'
73
73
  end
74
74
 
@@ -83,6 +83,10 @@ module Til
83
83
  @github_client ||= Octokit::Client.new(access_token: @env['GH_TOKEN'])
84
84
  end
85
85
 
86
+ def repo_name
87
+ @repo_name ||= @env['GH_REPO']
88
+ end
89
+
86
90
  def prompt_fzf(categories)
87
91
  reader1, writer1 = IO.pipe
88
92
  reader2, writer2 = IO.pipe
@@ -116,7 +120,7 @@ module Til
116
120
  end
117
121
 
118
122
  def open_editor
119
- editor = ENV['VISUAL'] || ENV['EDITOR']
123
+ editor = ENV['VISUAL'] || ENV['EDITOR'] || 'vi'
120
124
  system(*editor.split, @tempfile.path)
121
125
  end
122
126
 
@@ -135,13 +139,13 @@ module Til
135
139
  name = commit_title.split.map(&:downcase).join('-')
136
140
  filename = "#{today}_#{name}.md"
137
141
 
138
- ref = github_client.ref @repo_name, 'heads/master'
139
- commit = github_client.commit @repo_name, ref.object.sha
140
- tree = github_client.tree @repo_name, commit.commit.tree.sha, recursive: true
141
- readme = github_client.readme @repo_name
142
+ ref = github_client.ref repo_name, 'heads/master'
143
+ commit = github_client.commit repo_name, ref.object.sha
144
+ tree = github_client.tree repo_name, commit.commit.tree.sha, recursive: true
145
+ readme = github_client.readme repo_name
142
146
  readme_content = Base64.decode64 readme.content
143
147
 
144
- blob = github_client.create_blob @repo_name, content
148
+ blob = github_client.create_blob repo_name, content
145
149
  blobs = tree.tree.filter { |object|
146
150
  object[:type] == 'blob' && object[:path] != 'README.md'
147
151
  }.map { |object|
@@ -149,14 +153,14 @@ module Til
149
153
  }
150
154
 
151
155
  updated_readme_content = update_readme_content(category, commit_title, filename, readme_content)
152
- new_readme_blob = github_client.create_blob @repo_name, updated_readme_content
156
+ new_readme_blob = github_client.create_blob repo_name, updated_readme_content
153
157
  blobs << { path: 'README.md', mode: '100644', type: 'blob', sha: new_readme_blob }
154
158
 
155
159
  blobs << { path: "#{category}/#{filename}", mode: '100644', type: 'blob', sha: blob }
156
160
 
157
- tree = github_client.create_tree @repo_name, blobs
158
- commit = github_client.create_commit @repo_name, commit_title, tree.sha, ref.object.sha
159
- github_client.update_ref @repo_name, 'heads/master', commit.sha
161
+ tree = github_client.create_tree repo_name, blobs
162
+ commit = github_client.create_commit repo_name, commit_title, tree.sha, ref.object.sha
163
+ github_client.update_ref repo_name, 'heads/master', commit.sha
160
164
 
161
165
  puts "You can see your new TIL at : https://github.com/pjambet/til/blob/master/#{category}/#{filename}"
162
166
  puts "You can edit your new TIL at : https://github.com/pjambet/til/edit/master/#{category}/#{filename}"
@@ -1,5 +1,5 @@
1
1
  module Til
2
2
 
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: til-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Jambet