Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tie tide plugin #7

Merged
merged 2 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
push:
branches:
- main
tags:
- 'v*'

jobs:
buildx:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3.2.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8c0edbc76e98fa90f69d9a2c020dcb50019dc325 # v2.2.1
- name: Docker login
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker build
run: make release
- name: Docker build latest
run: VERSION=latest make release
- name: Docker build versioned
run: VERSION=${{ github.ref_name }} make release
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Test

on:
pull_request:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-local:
test:
go test -v --race ./...

VERSION ?= latest
VERSION ?= $(shell git describe --always)
IMAGE_REGISTRY ?= airconduct/kuilei
GOPROXY ?= https://proxy.golang.org,direct
release:
Expand Down
32 changes: 24 additions & 8 deletions pkg/plugins/internal/tide.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,18 @@ func (c *tideController) syncRepo(tideCtxVal *atomic.Value) {
return
}
for _, pr := range prs {
tideStatus, ok := getTideStatus(pr)
state, desc, merge := wantsStateAndDescription(pr, tideCtx.RequiredLabels, tideCtx.MissingLabels)
err := tideCtx.RepoClient.CreateStatus(ctx, tideCtx.Repo, pr.Head.Sha, plugins.GitCommitStatus{
State: state,
Context: statusContext,
Description: desc,
})
if err != nil {
tideCtx.Log.Error(err, "Failed to create status", "pr", pr.Number)
continue
if !ok || (tideStatus.State != state || tideStatus.Description != desc) {
err := tideCtx.RepoClient.CreateStatus(ctx, tideCtx.Repo, pr.Head.Sha, plugins.GitCommitStatus{
State: state,
Context: statusContext,
Description: desc,
})
if err != nil {
tideCtx.Log.Error(err, "Failed to create status", "pr", pr.Number)
continue
}
}
if !merge {
continue
Expand All @@ -182,6 +185,19 @@ func (c *tideController) syncRepo(tideCtxVal *atomic.Value) {
}, TideSyncInterval)
}

func getTideStatus(pr plugins.GitPullRequest) (plugins.GitCommitStatus, bool) {
for _, commit := range pr.Commits {
if commit.Sha == pr.Head.Sha {
for _, status := range commit.Statuses {
if status.Context == statusContext {
return status, true
}
}
}
}
return plugins.GitCommitStatus{}, false
}

func wantsStateAndDescription(pr plugins.GitPullRequest, required, missing []string) (state string, desc string, merge bool) {
// Check labels
currentLabels := sets.NewString()
Expand Down
15 changes: 15 additions & 0 deletions pkg/plugins/internal/tide_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/airconduct/kuilei/pkg/plugins"
"github.com/airconduct/kuilei/pkg/plugins/internal"
Expand All @@ -32,6 +33,7 @@ var _ = Describe("Plugin tide", func() {
{Sha: "foo"},
},
}
callCreateStatus := false

tide := plugins.GetGitCommentPlugin("tide", plugins.ClientSets{
GitPRClient: mock.FakeGitPRClient(
Expand All @@ -53,6 +55,7 @@ var _ = Describe("Plugin tide", func() {
"CreateStatus": func(ctx context.Context, repo plugins.GitRepo, ref string, status plugins.GitCommitStatus) error {
globalLock.Lock()
defer globalLock.Unlock()
callCreateStatus = true

var target *plugins.GitCommitStatus
for idx, s := range fakePR.Commits[0].Statuses {
Expand Down Expand Up @@ -113,6 +116,18 @@ var _ = Describe("Plugin tide", func() {
}, 5*time.Second, time.Second).Should(Succeed())
})

It("Should not create more status", func() {
globalLock.Lock()
callCreateStatus = false
globalLock.Unlock()

Expect(wait.PollImmediate(time.Second, 5*time.Second, func() (done bool, err error) {
globalLock.RLock()
defer globalLock.RUnlock()
return callCreateStatus == true, nil
})).ShouldNot(BeNil())
})

It("Should merge", func() {
Eventually(func(g Gomega) {
globalLock.RLock()
Expand Down
1 change: 0 additions & 1 deletion pkg/tide/controller.go

This file was deleted.