til-rb 0.0.6 → 0.0.7
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 +13 -0
- data/lib/til/core.rb +24 -9
- 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: 929173ad31be6464b75779784d2c1bb1d37f04d548b1869783e156bc1a13cb11
|
4
|
+
data.tar.gz: 351871aa23247e031ab56b163a3e3684b8cc995d8fe0dc65b6c529b851c51332
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce2a20ab053f5e3ed0f8bb68cd085beb60e87a5f45c39e9af95626714eb309275f6464b9d5690ad6b7eedf34b6d476999b890ac16e72db8b1fc2dc0a838eedb8
|
7
|
+
data.tar.gz: c418c12ae3bf2ee02255350c330b6271a07d0bcd053ea2b45acf762b852e5e0eb04daf4676bbec9980bfe803f2e6b83c598bd39e51075527fbf8233b9f2f4087
|
data/README.md
CHANGED
@@ -18,6 +18,16 @@ See it in action below:
|
|
18
18
|
gem install til-rb
|
19
19
|
```
|
20
20
|
|
21
|
+
You will also need `fzf` to run `til`, it's available on homebrew, so unless you already installed it, you'll have to run
|
22
|
+
|
23
|
+
```
|
24
|
+
brew install fzf
|
25
|
+
```
|
26
|
+
|
27
|
+
_fzf is technically not a hard requirement, we really could have a slightly different workflow if it's not available.
|
28
|
+
Given that I currently am the only user, there's no need to change this at the moment, but if you'd like to use this
|
29
|
+
gem without `fzf`, let me know and I'll happily work on it!_
|
30
|
+
|
21
31
|
### Step 2: Create a GitHub repo
|
22
32
|
|
23
33
|
You need a GitHub repo to store your TILs. The gem has pretty strict expectations about the format of the README.md
|
@@ -43,6 +53,9 @@ Add the following variables to your environment:
|
|
43
53
|
You might want to add those to either your `.bashrc` or `.zshrc` but please be careful in case you share those publicly
|
44
54
|
as the token is private and *must not* be shared publicly.
|
45
55
|
|
56
|
+
Note: An earlier version of this gem used different names, `GH_TOKEN` & `GH_REPO`, it still works, but is not the
|
57
|
+
recommended approach anymore, see #2.
|
58
|
+
|
46
59
|
### Step 4:
|
47
60
|
|
48
61
|
Run `til` from the command line
|
data/lib/til/core.rb
CHANGED
@@ -5,6 +5,9 @@ require 'readline'
|
|
5
5
|
module Til
|
6
6
|
class Core
|
7
7
|
|
8
|
+
GH_TOKEN_ENV_VAR_NAME = 'TIL_RB_GITHUB_TOKEN'
|
9
|
+
GH_REPO_ENV_VAR_NAME = 'TIL_RB_GITHUB_REPO'
|
10
|
+
|
8
11
|
def self.run(options: {})
|
9
12
|
# Exit if `fzf` is not available
|
10
13
|
# Optionally print a spinner
|
@@ -59,12 +62,20 @@ module Til
|
|
59
62
|
end
|
60
63
|
|
61
64
|
def check_environment_variables
|
62
|
-
if @env[
|
63
|
-
|
65
|
+
if @env[GH_TOKEN_ENV_VAR_NAME].nil? || @env[GH_TOKEN_ENV_VAR_NAME] == ''
|
66
|
+
if @env['GH_TOKEN'].nil? || @env['GH_TOKEN'] == ''
|
67
|
+
raise "The #{GH_TOKEN_ENV_VAR_NAME} (with the public_repo or repo scope) environment variable is required"
|
68
|
+
else
|
69
|
+
@stderr.puts "Using GH_TOKEN is deprecated, use #{GH_TOKEN_ENV_VAR_NAME} instead"
|
70
|
+
end
|
64
71
|
end
|
65
72
|
|
66
|
-
if @env[
|
67
|
-
|
73
|
+
if @env[GH_REPO_ENV_VAR_NAME].nil? || @env[GH_REPO_ENV_VAR_NAME] == ''
|
74
|
+
if @env['GH_REPO'].nil? || @env['GH_REPO'] == ''
|
75
|
+
raise "The #{GH_REPO_ENV_VAR_NAME} environment variable is required"
|
76
|
+
else
|
77
|
+
@stderr.puts "Using GH_REPO is deprecated, use #{GH_REPO_ENV_VAR_NAME} instead"
|
78
|
+
end
|
68
79
|
end
|
69
80
|
end
|
70
81
|
|
@@ -81,11 +92,11 @@ module Til
|
|
81
92
|
end
|
82
93
|
|
83
94
|
def github_client
|
84
|
-
@github_client ||= Octokit::Client.new(access_token: @env['GH_TOKEN'])
|
95
|
+
@github_client ||= Octokit::Client.new(access_token: @env[GH_TOKEN_ENV_VAR_NAME] || @env['GH_TOKEN'])
|
85
96
|
end
|
86
97
|
|
87
98
|
def repo_name
|
88
|
-
@repo_name ||= @env['GH_REPO']
|
99
|
+
@repo_name ||= (@env[GH_REPO_ENV_VAR_NAME] || @env['GH_REPO'])
|
89
100
|
end
|
90
101
|
|
91
102
|
def prompt_fzf(categories)
|
@@ -131,14 +142,18 @@ module Til
|
|
131
142
|
content
|
132
143
|
end
|
133
144
|
|
145
|
+
def new_filename(commit_title)
|
146
|
+
today = Time.now.strftime '%Y-%m-%d'
|
147
|
+
name = CGI.escape(commit_title.split.map(&:downcase).join('-'))
|
148
|
+
"#{today}_#{name}.md"
|
149
|
+
end
|
150
|
+
|
134
151
|
def commit_new_til(category, content)
|
135
152
|
commit_title = content.lines[0].chomp
|
136
153
|
if commit_title.start_with?('#')
|
137
154
|
commit_title = commit_title[1..].strip
|
138
155
|
end
|
139
|
-
|
140
|
-
name = commit_title.split.map(&:downcase).join('-')
|
141
|
-
filename = "#{today}_#{name}.md"
|
156
|
+
filename = new_filename(commit_title)
|
142
157
|
|
143
158
|
ref = github_client.ref repo_name, 'heads/master'
|
144
159
|
commit = github_client.commit repo_name, ref.object.sha
|
data/lib/til/version.rb
CHANGED