Skip to content

Instantly share code, notes, and snippets.

@chsh
Created April 26, 2014 15:54
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chsh/11323579 to your computer and use it in GitHub Desktop.
Save chsh/11323579 to your computer and use it in GitHub Desktop.
Create issue for GitLab and create task for Todoist same time.
#!/usr/bin/env ruby
require 'cgi'
gem 'gitlab'
gem 'todoist'
require 'gitlab'
require 'todoist'
class IssueCreator
def initialize
@url = configured_value 'issue.url'
@private_token = configured_value 'issue.apikey'
@client = Gitlab.client(endpoint: @url, private_token: @private_token)
@repo = configured_value 'issue.repo'
@project = @client.project(CGI.escape(@repo))
todoist_apikey = configured_value('todoist.apikey', global: true)
todoist_project_name = configured_value('todoist.project')
Todoist::Base.setup(todoist_apikey)
@todoist_project = Todoist::Project.all.select { |project|
project.name == todoist_project_name
}.first
end
def create(message)
issue = @client.create_issue @project.id, message, assignee_id: @client.user.id
issue_url = "#{@project.web_url}/issues/#{issue.iid}"
content = "#{message}\n#{issue_url} (#{@repo} ##{issue.iid})"
@todoist_project.add_task content, 'priority' => 1
end
def configured_value(name, opts = {})
opts[:trim] = true unless opts.key?(:trim)
opts[:global] = false unless opts.key?(:global)
res = `git config #{opts[:global] ? '--global ' : ''}#{name}`
res = opts[:trim] ? res.strip : res
res
end
end
if ARGV.size <= 0
puts "usage: #{$0} message"
else
runner = IssueCreator.new
runner.create ARGV[0]
end
@chsh
Copy link
Author

chsh commented Apr 26, 2014

しかしここで使っているtodoistというgemは最終更新が5年前で、指定できるパラメータも全然少なくてLabelに対応してなかったりとさすがにorzな感じ。forkして作り直すかなあ。

@1beb
Copy link

1beb commented Feb 17, 2016

Where did you put this to get it working?

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