-
-
Save alain-andre/bb77a8ac78411e94d2c37f9d0abcaac0 to your computer and use it in GitHub Desktop.
Create issue for GitLab and create task for Todoist same time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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