generated from atomicgo/template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repository.go
73 lines (62 loc) · 2 KB
/
repository.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package ghissue
import (
"fmt"
"runtime"
"strings"
)
// Repository is a GitHub repository.
type Repository struct {
Owner string
Name string
}
// NewRepository creates a new Repository from an owner and repository name.
func NewRepository(owner, name string) Repository {
return Repository{
Owner: owner,
Name: name,
}
}
// String returns the string representation of the repository.
func (repo Repository) String() string {
return fmt.Sprintf("%s/%s", repo.Owner, repo.Name)
}
// NewIssue creates a new issue with a title and body.
func (repo Repository) NewIssue(title, body string) Issue {
return NewIssue(repo, title, body)
}
// CreateErrorReport creates a new issue on GitHub with a detailed error report including the stack trace.
//
// Example:
//
// repo := ghissue.NewRepository("atomicgo", "ghissue")
// // [...]
// err := errors.New("This is an error")
// repo.CreateErrorReport(err)
func (repo Repository) CreateErrorReport(err error) error {
if err == nil {
return nil
}
title := fmt.Sprintf("[Error Report] `%s`", err.Error())
var report []string
report = append(report, "# Automatic Error Report")
report = append(report, "")
report = append(report, "## Error")
report = append(report, "")
report = append(report, fmt.Sprintf("```\n%s\n```", err))
report = append(report, "")
report = append(report, "## Operating System")
report = append(report, "")
report = append(report, "| Key | Value |")
report = append(report, "| --- | --- |")
report = append(report, fmt.Sprintf("| %s | %s |", "Operating System", runtime.GOOS))
report = append(report, fmt.Sprintf("| %s | %s |", "Architecture", runtime.GOARCH))
report = append(report, fmt.Sprintf("| %s | %s |", "Go Version", runtime.Version()))
report = append(report, "")
report = append(report, "## Stack Trace")
report = append(report, "")
report = append(report, "```")
report = append(report, getStackTrace())
report = append(report, "```")
body := strings.Join(report, "\n")
return repo.NewIssue(title, body).Open()
}