workflow-pr: maintainernship function signature change

This commit is contained in:
Adam Majer 2024-11-28 18:16:14 +01:00
parent cf101ef3f0
commit 60c0a118c9
2 changed files with 29 additions and 23 deletions

View File

@ -16,8 +16,8 @@ type GiteaMaintainershipInterface interface {
FetchMaintainershipFile(org, prj, branch string) ([]byte, error) FetchMaintainershipFile(org, prj, branch string) ([]byte, error)
} }
func parseMaintainerhipData(gitea GiteaMaintainershipInterface, org, pkg, branch string) (MaintainershipMap, error) { func parseMaintainerhipData(gitea GiteaMaintainershipInterface, org, prjGit, branch string) (MaintainershipMap, error) {
data, err := gitea.FetchMaintainershipFile(org, pkg, branch) data, err := gitea.FetchMaintainershipFile(org, prjGit, branch)
if err != nil || data == nil { if err != nil || data == nil {
return nil, err return nil, err
} }
@ -30,8 +30,8 @@ func parseMaintainerhipData(gitea GiteaMaintainershipInterface, org, pkg, branch
return maintainer, nil return maintainer, nil
} }
func MaintainerListForProject(gitea GiteaMaintainershipInterface, org, branch string) ([]string, error) { func MaintainerListForProject(gitea GiteaMaintainershipInterface, config common.AutogitConfig) ([]string, error) {
maintainer, err := parseMaintainerhipData(gitea, org, common.DefaultGitPrj, branch) maintainer, err := parseMaintainerhipData(gitea, config.Organization, config.GitProjectName, config.Branch)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -44,8 +44,8 @@ func MaintainerListForProject(gitea GiteaMaintainershipInterface, org, branch st
return m, nil return m, nil
} }
func MaintainerListForPackage(gitea GiteaMaintainershipInterface, org, pkg, branch string) ([]string, error) { func MaintainerListForPackage(gitea GiteaMaintainershipInterface, config common.AutogitConfig, pkg string) ([]string, error) {
maintainer, err := parseMaintainerhipData(gitea, org, pkg, branch) maintainer, err := parseMaintainerhipData(gitea, config.Organization, config.GitProjectName, config.Branch)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -19,12 +19,18 @@ func TestMaintainership(t *testing.T) {
return mi return mi
} }
config := common.AutogitConfig {
Branch: "bar",
Organization: "foo",
GitProjectName: common.DefaultGitPrj,
}
t.Run("No maintainer in empty package", func(t *testing.T) { t.Run("No maintainer in empty package", func(t *testing.T) {
mi := allocateMaintainershipInterface(t) mi := allocateMaintainershipInterface(t)
mi.EXPECT().FetchMaintainershipFile("foo", "goo", "bar").Return(nil, nil) mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return(nil, nil)
m, err := MaintainerListForPackage(mi, "foo", "goo", "bar") m, err := MaintainerListForPackage(mi, config, "bar")
if len(m) != 0 || err != nil { if len(m) != 0 || err != nil {
t.Error("Invalid number of maintainers for package", err) t.Error("Invalid number of maintainers for package", err)
} }
@ -35,14 +41,14 @@ func TestMaintainership(t *testing.T) {
mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return(nil, nil) mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return(nil, nil)
m, err := MaintainerListForProject(mi, "foo", "bar") m, err := MaintainerListForProject(mi, config)
if len(m) != 0 || err != nil { if len(m) != 0 || err != nil {
t.Error("Invalid number of maintainers for project", err) t.Error("Invalid number of maintainers for project", err)
} }
mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return([]byte("{}"), nil) mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return([]byte("{}"), nil)
m, err = MaintainerListForProject(mi, "foo", "bar") m, err = MaintainerListForProject(mi, config)
if len(m) != 0 || err != nil { if len(m) != 0 || err != nil {
t.Error("Invalid number of maintainers for project", err) t.Error("Invalid number of maintainers for project", err)
} }
@ -52,9 +58,9 @@ func TestMaintainership(t *testing.T) {
mi := allocateMaintainershipInterface(t) mi := allocateMaintainershipInterface(t)
err := errors.New("some error here") err := errors.New("some error here")
mi.EXPECT().FetchMaintainershipFile("foo", "goo", "bar").Return(nil, err) mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return(nil, err)
_, errRet := MaintainerListForPackage(mi, "foo", "goo", "bar") _, errRet := MaintainerListForPackage(mi, config, "bar")
switch errRet { switch errRet {
case nil: case nil:
t.Error("Should have returned an error") t.Error("Should have returned an error")
@ -71,7 +77,7 @@ func TestMaintainership(t *testing.T) {
err := errors.New("some error here") err := errors.New("some error here")
mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return(nil, err) mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return(nil, err)
_, errRet := MaintainerListForProject(mi, "foo", "bar") _, errRet := MaintainerListForProject(mi, config)
switch errRet { switch errRet {
case nil: case nil:
t.Error("Should have returned an error") t.Error("Should have returned an error")
@ -91,7 +97,7 @@ func TestMaintainership(t *testing.T) {
} }
`), nil) `), nil)
m, err := MaintainerListForProject(mi, "foo", "bar") m, err := MaintainerListForProject(mi, config)
if len(m) != 2 || err != nil { if len(m) != 2 || err != nil {
t.Error("Invalid number of maintainers for project", err) t.Error("Invalid number of maintainers for project", err)
} }
@ -110,7 +116,7 @@ func TestMaintainership(t *testing.T) {
} }
`), nil) `), nil)
m, err := MaintainerListForProject(mi, "foo", "bar") m, err := MaintainerListForProject(mi, config)
if len(m) != 1 || err != nil { if len(m) != 1 || err != nil {
t.Error("Invalid number of maintainers for project", err) t.Error("Invalid number of maintainers for project", err)
} }
@ -129,7 +135,7 @@ func TestMaintainership(t *testing.T) {
} }
`), nil) `), nil)
m, err := MaintainerListForProject(mi, "foo", "bar") m, err := MaintainerListForProject(mi, config)
if len(m) != 0 || err == nil { if len(m) != 0 || err == nil {
t.Error("Invalid number of maintainers for project", err) t.Error("Invalid number of maintainers for project", err)
} }
@ -144,7 +150,7 @@ func TestMaintainership(t *testing.T) {
} }
`), nil) `), nil)
_, err := MaintainerListForProject(mi, "foo", "bar") _, err := MaintainerListForProject(mi, config)
if err == nil { if err == nil {
t.Error("Invalid number of maintainers for project", err) t.Error("Invalid number of maintainers for project", err)
} }
@ -153,14 +159,14 @@ func TestMaintainership(t *testing.T) {
t.Run("Multiple package maintainers", func(t *testing.T) { t.Run("Multiple package maintainers", func(t *testing.T) {
mi := allocateMaintainershipInterface(t) mi := allocateMaintainershipInterface(t)
mi.EXPECT().FetchMaintainershipFile("foo", "pkg", "bar").Return([]byte(` mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return([]byte(`
{ {
"pkg": ["user1", "user2"], "pkg": ["user1", "user2"],
"": ["user1", "user3"] "": ["user1", "user3"]
} }
`), nil) `), nil)
m, err := MaintainerListForPackage(mi, "foo", "pkg", "bar") m, err := MaintainerListForPackage(mi, config, "pkg")
if len(m) != 3 || err != nil { if len(m) != 3 || err != nil {
t.Error("Invalid number of maintainers for package", m) t.Error("Invalid number of maintainers for package", m)
} }
@ -173,14 +179,14 @@ func TestMaintainership(t *testing.T) {
t.Run("No package maintainers and only project maintainer", func(t *testing.T) { t.Run("No package maintainers and only project maintainer", func(t *testing.T) {
mi := allocateMaintainershipInterface(t) mi := allocateMaintainershipInterface(t)
mi.EXPECT().FetchMaintainershipFile("foo", "pkg0", "bar").Return([]byte(` mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return([]byte(`
{ {
"pkg": ["user1", "user2"], "pkg": ["user1", "user2"],
"": ["user1", "user3"] "": ["user1", "user3"]
} }
`), nil) `), nil)
m, err := MaintainerListForPackage(mi, "foo", "pkg0", "bar") m, err := MaintainerListForPackage(mi, config, "bar")
if len(m) != 2 || err != nil { if len(m) != 2 || err != nil {
t.Error("Invalid number of maintainers for package", m) t.Error("Invalid number of maintainers for package", m)
} }
@ -193,14 +199,14 @@ func TestMaintainership(t *testing.T) {
t.Run("Invalid list of package maintainers", func(t *testing.T) { t.Run("Invalid list of package maintainers", func(t *testing.T) {
mi := allocateMaintainershipInterface(t) mi := allocateMaintainershipInterface(t)
mi.EXPECT().FetchMaintainershipFile("foo", "pkg", "bar").Return([]byte(` mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return([]byte(`
{ {
"pkg": 3, "pkg": 3,
"": ["user", 4] "": ["user", 4]
} }
`), nil) `), nil)
m, err := MaintainerListForPackage(mi, "foo", "pkg", "bar") m, err := MaintainerListForPackage(mi, config, "pkg")
if len(m) != 0 || err == nil { if len(m) != 0 || err == nil {
t.Error("Invalid number of maintainers for project", err) t.Error("Invalid number of maintainers for project", err)
} }