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.
- checksums.yaml +4 -4
- data/lib/til/core.rb +18 -14
- data/lib/til/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: 7663677e1c231cfb2bbba240e889b85ac2ae1c22519b0c365fa225e91ed876f9
|
4
|
+
data.tar.gz: 5404592be317f806bec787e4f21a444ddbb22e2fe680b1278b93ad8c0b3bff72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b98afb9724d5818dc13d5dc0d59cc3b1ceeed17e6b111f09d00159eb2dc943b4649c59009bb815a86c1fb82e833eff16d00630d2abd35a101ed815da9b736a4
|
7
|
+
data.tar.gz: 7c5ccdb8864eefe7b7242a066b7d517cfe966e52fa610d95f85f7dfb546b7f97c2575d0eb7e75cde810d3ef1d7e3948def5f1bf370d9cee741d833995a28d63a
|
data/lib/til/core.rb
CHANGED
@@ -28,7 +28,7 @@ module Til
|
|
28
28
|
@env = env
|
29
29
|
@stderr = stderr
|
30
30
|
@github_client = github_client
|
31
|
-
@repo_name =
|
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
|
66
|
-
raise 'The
|
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(
|
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
|
139
|
-
commit = github_client.commit
|
140
|
-
tree = github_client.tree
|
141
|
-
readme = github_client.readme
|
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
|
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
|
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
|
158
|
-
commit = github_client.create_commit
|
159
|
-
github_client.update_ref
|
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}"
|
data/lib/til/version.rb
CHANGED