2020-01-24 16:30:16 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
const defaultGitea = "https://gitea.com"
|
|
|
|
|
2020-08-04 13:30:19 +00:00
|
|
|
// New returns a service from a string
|
2022-03-13 02:33:03 +00:00
|
|
|
func New(serviceType, repo, baseURL, milestone, tag, token string, issues bool) (Service, error) {
|
|
|
|
if len(tag) == 0 {
|
|
|
|
tag = milestone
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:30:16 +00:00
|
|
|
switch strings.ToLower(serviceType) {
|
|
|
|
case "github":
|
|
|
|
return &GitHub{
|
|
|
|
Milestone: milestone,
|
2022-03-13 02:33:03 +00:00
|
|
|
GitTag: tag,
|
2020-01-24 16:30:16 +00:00
|
|
|
Token: token,
|
|
|
|
Repo: repo,
|
2020-08-04 13:30:19 +00:00
|
|
|
Issues: issues,
|
2020-01-24 16:30:16 +00:00
|
|
|
}, nil
|
|
|
|
case "gitea":
|
|
|
|
ownerRepo := strings.Split(repo, "/")
|
|
|
|
if strings.TrimSpace(baseURL) == "" {
|
|
|
|
baseURL = defaultGitea
|
|
|
|
}
|
|
|
|
return &Gitea{
|
|
|
|
Milestone: milestone,
|
2022-03-13 02:33:03 +00:00
|
|
|
GitTag: tag,
|
2020-01-24 16:30:16 +00:00
|
|
|
Token: token,
|
|
|
|
BaseURL: baseURL,
|
|
|
|
Owner: ownerRepo[0],
|
|
|
|
Repo: ownerRepo[1],
|
2020-08-04 13:30:19 +00:00
|
|
|
Issues: issues,
|
2020-01-24 16:30:16 +00:00
|
|
|
}, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unknown service type %s", serviceType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Service defines how a struct can be a Changelog Service
|
|
|
|
type Service interface {
|
2020-08-04 13:30:19 +00:00
|
|
|
Generate() (string, []Entry, error)
|
2020-01-24 16:30:16 +00:00
|
|
|
Contributors() (ContributorList, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Label is the minimum information needed for a PR label
|
|
|
|
type Label struct {
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
2020-08-04 13:30:19 +00:00
|
|
|
// Entry is the minimum information needed to make a changelog entry
|
|
|
|
type Entry struct {
|
2020-01-24 16:30:16 +00:00
|
|
|
Title string
|
|
|
|
Index int64
|
|
|
|
Labels []Label
|
|
|
|
}
|
|
|
|
|
|
|
|
// Contributor is a project contributor
|
|
|
|
type Contributor struct {
|
|
|
|
Name string
|
|
|
|
Profile string
|
|
|
|
}
|
|
|
|
|
|
|
|
// ContributorList is a slice of Contributors that can be sorted
|
|
|
|
type ContributorList []Contributor
|
|
|
|
|
|
|
|
// Len is the length of the ContributorList
|
|
|
|
func (cl ContributorList) Len() int {
|
|
|
|
return len(cl)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Less determines whether a Contributor comes before another Contributor
|
|
|
|
func (cl ContributorList) Less(i, j int) bool {
|
|
|
|
return cl[i].Name < cl[j].Name
|
|
|
|
}
|
|
|
|
|
|
|
|
// Swap swaps Contributors in a ContributorList
|
|
|
|
func (cl ContributorList) Swap(i, j int) {
|
|
|
|
cl[i], cl[j] = cl[j], cl[i]
|
|
|
|
}
|