From 60c0a118c94ece9e4caba7fb1f6d9119e8de60c2b89a8803f9c0303221f66a2a Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Thu, 28 Nov 2024 18:16:14 +0100 Subject: [PATCH] workflow-pr: maintainernship function signature change --- workflow-pr/maintainership.go | 12 ++++----- workflow-pr/maintainership_test.go | 40 +++++++++++++++++------------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/workflow-pr/maintainership.go b/workflow-pr/maintainership.go index d074490..389600c 100644 --- a/workflow-pr/maintainership.go +++ b/workflow-pr/maintainership.go @@ -16,8 +16,8 @@ type GiteaMaintainershipInterface interface { FetchMaintainershipFile(org, prj, branch string) ([]byte, error) } -func parseMaintainerhipData(gitea GiteaMaintainershipInterface, org, pkg, branch string) (MaintainershipMap, error) { - data, err := gitea.FetchMaintainershipFile(org, pkg, branch) +func parseMaintainerhipData(gitea GiteaMaintainershipInterface, org, prjGit, branch string) (MaintainershipMap, error) { + data, err := gitea.FetchMaintainershipFile(org, prjGit, branch) if err != nil || data == nil { return nil, err } @@ -30,8 +30,8 @@ func parseMaintainerhipData(gitea GiteaMaintainershipInterface, org, pkg, branch return maintainer, nil } -func MaintainerListForProject(gitea GiteaMaintainershipInterface, org, branch string) ([]string, error) { - maintainer, err := parseMaintainerhipData(gitea, org, common.DefaultGitPrj, branch) +func MaintainerListForProject(gitea GiteaMaintainershipInterface, config common.AutogitConfig) ([]string, error) { + maintainer, err := parseMaintainerhipData(gitea, config.Organization, config.GitProjectName, config.Branch) if err != nil { return nil, err } @@ -44,8 +44,8 @@ func MaintainerListForProject(gitea GiteaMaintainershipInterface, org, branch st return m, nil } -func MaintainerListForPackage(gitea GiteaMaintainershipInterface, org, pkg, branch string) ([]string, error) { - maintainer, err := parseMaintainerhipData(gitea, org, pkg, branch) +func MaintainerListForPackage(gitea GiteaMaintainershipInterface, config common.AutogitConfig, pkg string) ([]string, error) { + maintainer, err := parseMaintainerhipData(gitea, config.Organization, config.GitProjectName, config.Branch) if err != nil { return nil, err } diff --git a/workflow-pr/maintainership_test.go b/workflow-pr/maintainership_test.go index b1f3a9d..568249f 100644 --- a/workflow-pr/maintainership_test.go +++ b/workflow-pr/maintainership_test.go @@ -19,12 +19,18 @@ func TestMaintainership(t *testing.T) { return mi } + config := common.AutogitConfig { + Branch: "bar", + Organization: "foo", + GitProjectName: common.DefaultGitPrj, + } + t.Run("No maintainer in empty package", func(t *testing.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 { 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) - m, err := MaintainerListForProject(mi, "foo", "bar") + m, err := MaintainerListForProject(mi, config) if len(m) != 0 || err != nil { t.Error("Invalid number of maintainers for project", err) } 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 { t.Error("Invalid number of maintainers for project", err) } @@ -52,9 +58,9 @@ func TestMaintainership(t *testing.T) { mi := allocateMaintainershipInterface(t) 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 { case nil: t.Error("Should have returned an error") @@ -71,7 +77,7 @@ func TestMaintainership(t *testing.T) { err := errors.New("some error here") mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return(nil, err) - _, errRet := MaintainerListForProject(mi, "foo", "bar") + _, errRet := MaintainerListForProject(mi, config) switch errRet { case nil: t.Error("Should have returned an error") @@ -91,7 +97,7 @@ func TestMaintainership(t *testing.T) { } `), nil) - m, err := MaintainerListForProject(mi, "foo", "bar") + m, err := MaintainerListForProject(mi, config) if len(m) != 2 || err != nil { t.Error("Invalid number of maintainers for project", err) } @@ -110,7 +116,7 @@ func TestMaintainership(t *testing.T) { } `), nil) - m, err := MaintainerListForProject(mi, "foo", "bar") + m, err := MaintainerListForProject(mi, config) if len(m) != 1 || err != nil { t.Error("Invalid number of maintainers for project", err) } @@ -129,7 +135,7 @@ func TestMaintainership(t *testing.T) { } `), nil) - m, err := MaintainerListForProject(mi, "foo", "bar") + m, err := MaintainerListForProject(mi, config) if len(m) != 0 || err == nil { t.Error("Invalid number of maintainers for project", err) } @@ -144,7 +150,7 @@ func TestMaintainership(t *testing.T) { } `), nil) - _, err := MaintainerListForProject(mi, "foo", "bar") + _, err := MaintainerListForProject(mi, config) if err == nil { 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) { mi := allocateMaintainershipInterface(t) - mi.EXPECT().FetchMaintainershipFile("foo", "pkg", "bar").Return([]byte(` + mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return([]byte(` { "pkg": ["user1", "user2"], "": ["user1", "user3"] } `), nil) - m, err := MaintainerListForPackage(mi, "foo", "pkg", "bar") + m, err := MaintainerListForPackage(mi, config, "pkg") if len(m) != 3 || err != nil { 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) { mi := allocateMaintainershipInterface(t) - mi.EXPECT().FetchMaintainershipFile("foo", "pkg0", "bar").Return([]byte(` + mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return([]byte(` { "pkg": ["user1", "user2"], "": ["user1", "user3"] } `), nil) - m, err := MaintainerListForPackage(mi, "foo", "pkg0", "bar") + m, err := MaintainerListForPackage(mi, config, "bar") if len(m) != 2 || err != nil { 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) { mi := allocateMaintainershipInterface(t) - mi.EXPECT().FetchMaintainershipFile("foo", "pkg", "bar").Return([]byte(` + mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return([]byte(` { "pkg": 3, "": ["user", 4] } `), nil) - m, err := MaintainerListForPackage(mi, "foo", "pkg", "bar") + m, err := MaintainerListForPackage(mi, config, "pkg") if len(m) != 0 || err == nil { t.Error("Invalid number of maintainers for project", err) }