Skip to content

Instantly share code, notes, and snippets.

@alain-andre
Forked from chsh/git-issue
Created May 30, 2016 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alain-andre/bb77a8ac78411e94d2c37f9d0abcaac0 to your computer and use it in GitHub Desktop.
Save alain-andre/bb77a8ac78411e94d2c37f9d0abcaac0 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment