diff --git a/changelog.go b/changelog.go index 957e6d5..63c049c 100644 --- a/changelog.go +++ b/changelog.go @@ -49,12 +49,16 @@ func (cl *ChangeLog) filterReleases(rels []*github.RepositoryRelease) []*github. } // Generate generates changelog text from given releases and outputs it to its writer -func (cl *ChangeLog) Generate(rels []*github.RepositoryRelease) error { +func (cl *ChangeLog) Generate(rels []*github.RepositoryRelease, links []*github.Autolink) error { rels = cl.filterReleases(rels) out := bufio.NewWriter(cl.out) heading := strings.Repeat("#", cl.level) + linker := NewReflinker(cl.repoURL) + for _, l := range links { + linker.AddExtRef(*l.KeyPrefix, *l.URLTemplate, *l.IsAlphanumeric) + } numRels := len(rels) relLinks := make([]link, 0, numRels) diff --git a/github.go b/github.go index 0cfbd83..9568f73 100644 --- a/github.go +++ b/github.go @@ -41,13 +41,30 @@ func (gh *GitHub) Releases() ([]*github.RepositoryRelease, error) { } } +func (gh *GitHub) CustomAutolinks() ([]*github.Autolink, error) { + links := []*github.Autolink{} + page := 1 + for { + opts := github.ListOptions{Page: page} + ls, res, err := gh.api.Repositories.ListAutolinks(gh.apiCtx, gh.owner, gh.repoName, &opts) + if err != nil { + return nil, fmt.Errorf("cannot get custom autolinks from repository %s/%s via GitHub API: %w", gh.owner, gh.repoName, err) + } + links = append(links, ls...) + if res.NextPage == 0 { + return links, nil + } + page = res.NextPage + } +} + // NewGitHub creates GitHub instance from given repository URL func NewGitHub(u *url.URL) (*GitHub, error) { // '/owner/name' path := strings.TrimSuffix(u.Path, ".git") slug := strings.Split(path, "/") if len(slug) != 3 { - return nil, fmt.Errorf("invalid slug of GitHub repo: %s", path) + return nil, fmt.Errorf("invalid slug in GitHub repository URL path: %s", path) } ctx := context.Background() diff --git a/main.go b/main.go index 65ca49b..5e51500 100644 --- a/main.go +++ b/main.go @@ -91,10 +91,14 @@ func main() { if err != nil { fail(err) } + ls, err := gh.CustomAutolinks() + if err != nil { + fail(err) + } cl := NewChangeLog(os.Stdout, url, *heading, *drafts, reIgnore, reExtract) - if err := cl.Generate(rels); err != nil { + if err := cl.Generate(rels, ls); err != nil { fail(err) } }