diff --git a/bots-common/git_utils.go b/bots-common/git_utils.go index ba57c82..2b14f7b 100644 --- a/bots-common/git_utils.go +++ b/bots-common/git_utils.go @@ -45,6 +45,7 @@ type GitStatusLister interface { } type Git interface { + GitCatFile(cwd, commitId, filename string) (data []byte, err error) GetPath() string CloneDevel(gitDir, outName, urlString string) error diff --git a/obs-staging-bot/main.go b/obs-staging-bot/main.go index 7a1f39a..c7aec77 100644 --- a/obs-staging-bot/main.go +++ b/obs-staging-bot/main.go @@ -55,9 +55,9 @@ func failOnError(err error, msg string) { } } -func fetchPrGit(git *common.GitHandler, pr *models.PullRequest) error { +func fetchPrGit(git common.Git, pr *models.PullRequest) error { // clone PR head and base and return path - if _, err := os.Stat(path.Join(git.GitPath, pr.Head.Sha)); os.IsNotExist(err) { + if _, err := os.Stat(path.Join(git.GetPath(), pr.Head.Sha)); os.IsNotExist(err) { git.GitExec("", "clone", "--depth", "1", pr.Head.Repo.CloneURL, pr.Head.Sha) git.GitExec(pr.Head.Sha, "fetch", "--depth", "1", "origin", pr.Head.Sha, pr.Base.Sha) } else if err != nil { @@ -234,7 +234,7 @@ func processRepoBuildStatus(results, ref []common.PackageBuildStatus) BuildStatu return BuildStatusSummarySuccess } -func generateObsPrjMeta(git *common.GitHandler, gitea common.Gitea, pr *models.PullRequest, obsClient *common.ObsClient) (*common.ProjectMeta, error) { +func generateObsPrjMeta(git common.Git, gitea common.Gitea, pr *models.PullRequest, obsClient *common.ObsClient) (*common.ProjectMeta, error) { log.Println("repo content fetching ...") err := fetchPrGit(git, pr) if err != nil { @@ -312,7 +312,7 @@ func generateObsPrjMeta(git *common.GitHandler, gitea common.Gitea, pr *models.P return meta, nil } -func startOrUpdateBuild(git *common.GitHandler, gitea common.Gitea, pr *models.PullRequest, obsClient *common.ObsClient) error { +func startOrUpdateBuild(git common.Git, gitea common.Gitea, pr *models.PullRequest, obsClient *common.ObsClient) error { log.Println("fetching OBS project Meta") obsPrProject := getObsProjectAssociatedWithPr(obsClient.HomeProject, pr) meta, err := obsClient.GetProjectMeta(obsPrProject) @@ -362,7 +362,7 @@ func processPullNotification(gitea common.Gitea, thread *models.NotificationThre } }() - gh := common.GitHandlerImpl{} + gh := common.GitHandlerGeneratorImpl{} git, err := gh.CreateGitHandler(GitAuthor, "noaddress@suse.de", BotName) if err != nil { log.Panicln(err) @@ -384,11 +384,16 @@ func processPullNotification(gitea common.Gitea, thread *models.NotificationThre repo := match[2] id, _ := strconv.ParseInt(match[3], 10, 64) - pr, reviews, err := gitea.GetPullRequestAndReviews(org, repo, id) + pr, err := gitea.GetPullRequest(org, repo, id) if err != nil { log.Println("No PR associated with review:", notification.URL, "Error:", err) return } + reviews, err := gitea.GetPullRequestReviews(org, repo, id) + if err != nil { + log.Println("No reviews associated with request:", notification.URL, "Error:", err) + return + } obsClient, err := common.NewObsClient("api.opensuse.org") if err != nil {