-
Notifications
You must be signed in to change notification settings - Fork 42
/
create-assigned-issue
executable file
·39 lines (32 loc) · 1.27 KB
/
create-assigned-issue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/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