Created
May 30, 2020 21:23
-
-
Save lukaspj/4f3fed8afa16f2f8e7c85aa9605b1fa3 to your computer and use it in GitHub Desktop.
This file contains 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
package main | |
import ( | |
"bufio" | |
"fmt" | |
"github.com/github/hub/github" | |
"log" | |
"os" | |
"strconv" | |
) | |
func main() { | |
issuesToMigrateString := GetIssuesToMigrate() | |
var issuesToMigrate []int | |
for _, issue := range issuesToMigrateString { | |
i, _ := strconv.Atoi(issue) | |
issuesToMigrate = append(issuesToMigrate, i) | |
} | |
fromProject := &github.Project{ | |
Name: "Torque3D", | |
Owner: "GarageGames", | |
Host: "github.com", | |
Protocol: "https", | |
} | |
toProject := &github.Project{ | |
Name: "Torque3D", | |
Owner: "Torque3D", | |
Host: "github.com", | |
Protocol: "https", | |
} | |
gh := github.NewClient(fromProject.Host) | |
filters := map[string]interface{}{} | |
issues, err := gh.FetchIssues(fromProject, filters, 0, func(issue *github.Issue) bool { | |
if issue.PullRequest != nil { | |
return false | |
} | |
for _, ino := range issuesToMigrate { | |
if ino == issue.Number { | |
return true | |
} | |
} | |
return false | |
}) | |
if err != nil { | |
fmt.Printf("Failed to get issues: %v", err) | |
return | |
} | |
for _, issue := range issues { | |
_, _ = gh.CreateIssue(toProject, map[string]interface{}{ | |
"title": issue.Title, | |
"body": fmt.Sprintf( | |
`This issue was created in the [GarageGames Repository](https://github.com/GarageGames/Torque3D) ([Link to original issue](https://github.com/GarageGames/Torque3D/issues/%d)). | |
The issue was originally created by @%s and had a total of %d comments that may contain additional information. The original issue description is pasted below: | |
%s | |
`, issue.Number, issue.User.Login, issue.Comments, issue.Body), | |
}) | |
} | |
} | |
func GetIssuesToMigrate() []string { | |
file, err := os.Open("issues_to_migrate.txt") | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer file.Close() | |
var output []string | |
scanner := bufio.NewScanner(file) | |
for scanner.Scan() { | |
output = append(output, scanner.Text()) | |
} | |
if err := scanner.Err(); err != nil { | |
log.Fatal(err) | |
} | |
return output | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment