40 строки
1.3 KiB
Ruby
Executable File
40 строки
1.3 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
banner = <<-BANNER
|
|
Usage: create-assigned-issue <issue URL>
|
|
* Copies issue as template
|
|
* Replaces any references to the assigned user (eg, at-mentions, etc.)
|
|
* Also "undoes" any checkboxes in issue template (eg, [x] -> [ ])
|
|
* For each collaborator of repo, creates a new issue, assigned to collaborator
|
|
BANNER
|
|
|
|
$stderr.sync = true
|
|
require 'octokit'
|
|
require 'optparse'
|
|
require_relative 'common'
|
|
|
|
file = __FILE__
|
|
issue_url = ARGV.first
|
|
|
|
abort banner if !issue_url || issue_url == '-h'
|
|
|
|
Octokit.auto_paginate = true
|
|
|
|
client = Octokit::Client.new :access_token => ENV['GITHUBTEACHER_TOKEN']
|
|
repo, number = parse_issue_url(issue_url)
|
|
issue = client.issue(repo, number)
|
|
assigned = issue.assignee.login
|
|
template = issue.body.gsub("[x] ", "[ ] ")
|
|
template = template.gsub("#{assigned}", "%{assignee}")
|
|
title = issue.title
|
|
title = title.gsub("#{assigned}", "%{assignee}")
|
|
|
|
client.collaborators(repo).each do |collaborator|
|
|
next if assigned == collaborator[:login]
|
|
title = title % { assignee: collaborator[:login] }
|
|
body = template % { assignee: collaborator[:login] }
|
|
assignee = collaborator[:login]
|
|
|
|
puts "Creating assigned issue for @#{collaborator[:login]}"
|
|
client.create_issue repo, title, body, assignee: assignee
|
|
end
|