Skip to content

Instantly share code, notes, and snippets.

@1stvamp
Last active March 26, 2024 13:54
Show Gist options
  • Save 1stvamp/5aa583734f23c2e511c380f170d46556 to your computer and use it in GitHub Desktop.
Save 1stvamp/5aa583734f23c2e511c380f170d46556 to your computer and use it in GitHub Desktop.
Script to fetch a gist with markdown in it and generate a nice standup post for Slack
#!/home/wes/.asdf/installs/ruby/3.0.2/bin/ruby
require 'uri'
require 'net/http'
NOCACHE_SUFFIX = 'nocache=' + Time.now.to_i.to_s
def break_cache(url)
url + (if url.include?('?') then '&' else '?' end) + NOCACHE_SUFFIX
end
uri = URI(break_cache(ENV['STANDUP_GIST_URL']))
begin
res = Net::HTTP.get_response(uri, { 'Cache-Control' => 'no-cache' })
uri = URI(break_cache(res['location'])) unless res['location'].nil?
end while res.is_a?(Net::HTTPRedirection)
lines = {
'done' => [],
'wip' => [],
'paused' => [],
'todo' => [],
'cancelled' => [],
}
res.body.split("\n").each do |line|
type = case line
when /\[ \] wip/
'wip'
when /\[ \] paused/
'paused'
when /\[(x| )\] ~/
'cancelled'
when /\[x\]/
'done'
else
'todo'
end
lines[type] << line.gsub(/^- /, '> ') \
.gsub('[ ] wip', ':checkbox-deferred:') \
.gsub('[ ] paused', ':double_vertical_bar:') \
.gsub(/\[(x| )\] ~/, ':checkbox-x: ~') \
.gsub('[x] wip', ':checkbox-checked:') \
.gsub('[x] paused', ':checkbox-checked:') \
.gsub('[x]', ':checkbox-checked:') \
.gsub('[ ]', ':checkbox-unchecked:')
end
unless lines['done'].empty?
puts lines['done'].join("\n")
puts
end
unless lines['wip'].empty?
puts lines['wip'].join("\n")
puts
end
unless lines['paused'].empty?
puts lines['paused'].join("\n")
puts
end
unless lines['todo'].empty?
puts lines['todo'].join("\n")
puts
end
unless lines['cancelled'].empty?
puts lines['cancelled'].join("\n")
end

:checkbox-checked: I did this thing :checkbox-checked: I did this thing too

:checkbox-deferred: I'm still doing this thing :checkbox-deferred: Still doing this

:double_vertical_bar: This thing has been paused until later

:checkbox-unchecked: I'm going to do this :checkbox-unchecked: I'm planning on doing this

:checkbox-x: This thing didn't happen

  • I did this thing
  • wip I did this thing too
  • wip I'm still doing this thing
  • wip Still doing this
  • I'm going to do this
  • I'm planning on doing this
  • This thing didn't happen
  • paused This thing has been paused until later
#!/home/wes/.asdf/installs/ruby/3.0.2/bin/ruby
require 'uri'
require 'net/http'
NOCACHE_SUFFIX = 'nocache=' + Time.now.to_i.to_s
def break_cache(url)
url + (if url.include?('?') then '&' else '?' end) + NOCACHE_SUFFIX
end
uri = URI(break_cache(ENV['STANDUP_GIST_URL']))
begin
res = Net::HTTP.get_response(uri, { 'Cache-Control' => 'no-cache' })
uri = URI(break_cache(res['location'])) unless res['location'].nil?
end while res.is_a?(Net::HTTPRedirection)
lines = []
res.body.split("\n").each do |line|
case line
when /\[x\]/
next
end
lines << line
end
puts lines.join("\n")

Get the raw URL for the markdown file in your gist, or could be from a github, gitlab or anywhere you can host a markdown file really

export STANDUP_GIST_URL='https://gist.github.com/1stvamp/blaaaaaaaaaaaaaaaaaaaaah/raw/standup.md'
alias standup='~/bin/create-standup.rb | xclip -selection c'
$ standup

The Slack markdown formatted standup should now be in your clipboard, if you paste this in to the standups channel Slack should ask you: image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment