refactor sourcehut manifest building
This commit is contained in:
parent
d5bd212d00
commit
faf1c836eb
|
@ -8,6 +8,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -189,11 +190,11 @@ func (pc sourcehutConvertor) Package(_ *api.PackagePayload) (graphqlPayload[buil
|
||||||
return graphqlPayload[buildsVariables]{}, shared.ErrPayloadTypeNotSupported
|
return graphqlPayload[buildsVariables]{}, shared.ErrPayloadTypeNotSupported
|
||||||
}
|
}
|
||||||
|
|
||||||
// mustBuildManifest adjusts the manifest to submit to the builds service
|
// newPayload opens and adjusts the manifest to submit to the builds service
|
||||||
//
|
//
|
||||||
// in case of an error the Error field will be set, to be visible by the end-user under recent deliveries
|
// in case of an error the Error field will be set, to be visible by the end-user under recent deliveries
|
||||||
func (pc sourcehutConvertor) newPayload(repo *api.Repository, commitID, ref, note string, trusted bool) (graphqlPayload[buildsVariables], error) {
|
func (pc sourcehutConvertor) newPayload(repo *api.Repository, commitID, ref, note string, trusted bool) (graphqlPayload[buildsVariables], error) {
|
||||||
manifest, err := pc.buildManifest(repo, commitID, ref)
|
manifest, err := pc.constructManifest(repo, commitID, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if len(manifest) == 0 {
|
if len(manifest) == 0 {
|
||||||
return graphqlPayload[buildsVariables]{}, err
|
return graphqlPayload[buildsVariables]{}, err
|
||||||
|
@ -238,9 +239,9 @@ func (pc sourcehutConvertor) newPayload(repo *api.Repository, commitID, ref, not
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildManifest adjusts the manifest to submit to the builds service
|
// constructManifest opens and adjusts the manifest to submit to the builds service
|
||||||
// in case of an error the []byte might contain an error that can be displayed to the user
|
// in case of an error the []byte might contain an error that can be displayed to the user
|
||||||
func (pc sourcehutConvertor) buildManifest(repo *api.Repository, commitID, gitRef string) ([]byte, error) {
|
func (pc sourcehutConvertor) constructManifest(repo *api.Repository, commitID, gitRef string) ([]byte, error) {
|
||||||
gitRepo, err := gitrepo.OpenRepository(pc.ctx, repo)
|
gitRepo, err := gitrepo.OpenRepository(pc.ctx, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := "could not open repository"
|
msg := "could not open repository"
|
||||||
|
@ -265,6 +266,10 @@ func (pc sourcehutConvertor) buildManifest(repo *api.Repository, commitID, gitRe
|
||||||
}
|
}
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
|
return adjustManifest(repo, commitID, gitRef, r, pc.meta.ManifestPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
func adjustManifest(repo *api.Repository, commitID, gitRef string, r io.Reader, path string) ([]byte, error) {
|
||||||
// reference: https://man.sr.ht/builds.sr.ht/manifest.md
|
// reference: https://man.sr.ht/builds.sr.ht/manifest.md
|
||||||
var manifest struct {
|
var manifest struct {
|
||||||
Sources []string `yaml:"sources"`
|
Sources []string `yaml:"sources"`
|
||||||
|
@ -273,7 +278,7 @@ func (pc sourcehutConvertor) buildManifest(repo *api.Repository, commitID, gitRe
|
||||||
Rest map[string]yaml.Node `yaml:",inline"`
|
Rest map[string]yaml.Node `yaml:",inline"`
|
||||||
}
|
}
|
||||||
if err := yaml.NewDecoder(r).Decode(&manifest); err != nil {
|
if err := yaml.NewDecoder(r).Decode(&manifest); err != nil {
|
||||||
msg := fmt.Sprintf("could not decode manifest %q", pc.meta.ManifestPath)
|
msg := fmt.Sprintf("could not decode manifest %q", path)
|
||||||
return []byte(msg), fmt.Errorf(msg+": %w", err)
|
return []byte(msg), fmt.Errorf(msg+": %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue