Compare commits
1 Commits
fix/gitea-
...
env-disabl
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
58f410befc |
8
Makefile
8
Makefile
@@ -1,8 +1,4 @@
|
||||
MODULES := devel-importer utils/hujson utils/maintainer-update gitea-events-rabbitmq-publisher gitea_status_proxy group-review obs-forward-bot obs-staging-bot obs-status-service workflow-direct workflow-pr
|
||||
|
||||
.PHONY: build $(MODULES)
|
||||
|
||||
build: $(MODULES)
|
||||
|
||||
$(MODULES):
|
||||
go build -C $@ -buildmode=pie
|
||||
build:
|
||||
for m in $(MODULES); do go build -C $$m -buildmode=pie || exit 1 ; done
|
||||
|
||||
@@ -221,14 +221,11 @@ type Gitea interface {
|
||||
GetPullRequests(org, project string) ([]*models.PullRequest, error)
|
||||
|
||||
GetCurrentUser() (*models.User, error)
|
||||
SetCacheTTL(ttl time.Duration)
|
||||
GetCacheTTL() time.Duration
|
||||
}
|
||||
|
||||
type GiteaTransport struct {
|
||||
transport *transport.Runtime
|
||||
client *apiclient.GiteaAPI
|
||||
cacheTTL time.Duration
|
||||
}
|
||||
|
||||
func AllocateGiteaTransport(giteaUrl string) Gitea {
|
||||
@@ -243,19 +240,10 @@ func AllocateGiteaTransport(giteaUrl string) Gitea {
|
||||
r.transport.DefaultAuthentication = transport.BearerToken(giteaToken)
|
||||
|
||||
r.client = apiclient.New(r.transport, nil)
|
||||
r.cacheTTL = time.Second * 5
|
||||
|
||||
return &r
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) SetCacheTTL(ttl time.Duration) {
|
||||
gitea.cacheTTL = ttl
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetCacheTTL() time.Duration {
|
||||
return gitea.cacheTTL
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) FetchMaintainershipFile(org, repo, branch string) ([]byte, string, error) {
|
||||
return gitea.GetRepositoryFileContent(org, repo, branch, MaintainershipFile)
|
||||
}
|
||||
@@ -869,19 +857,20 @@ func (gitea *GiteaTransport) ResetTimelineCache(org, repo string, idx int64) {
|
||||
func (gitea *GiteaTransport) GetTimeline(org, repo string, idx int64) ([]*models.TimelineComment, error) {
|
||||
page := int64(1)
|
||||
resCount := 1
|
||||
disableCache := GetEnvOverrideBool(os.Getenv("AUTOGITS_TIMELINE_CACHE_DISABLE"), false)
|
||||
|
||||
prID := fmt.Sprintf("%s/%s!%d", org, repo, idx)
|
||||
giteaTimelineCacheMutex.RLock()
|
||||
TimelineCache, IsCached := giteaTimelineCache[prID]
|
||||
var LastCachedTime strfmt.DateTime
|
||||
if IsCached {
|
||||
if IsCached && !disableCache {
|
||||
l := len(TimelineCache.data)
|
||||
if l > 0 {
|
||||
LastCachedTime = TimelineCache.data[0].Updated
|
||||
}
|
||||
|
||||
// cache data
|
||||
if TimelineCache.lastCheck.Add(gitea.cacheTTL).Compare(time.Now()) > 0 {
|
||||
// cache data for 5 seconds
|
||||
if TimelineCache.lastCheck.Add(time.Second*5).Compare(time.Now()) > 0 {
|
||||
giteaTimelineCacheMutex.RUnlock()
|
||||
return TimelineCache.data, nil
|
||||
}
|
||||
@@ -891,6 +880,10 @@ func (gitea *GiteaTransport) GetTimeline(org, repo string, idx int64) ([]*models
|
||||
giteaTimelineCacheMutex.Lock()
|
||||
defer giteaTimelineCacheMutex.Unlock()
|
||||
|
||||
if disableCache {
|
||||
TimelineCache = TimelineCacheData{}
|
||||
}
|
||||
|
||||
for resCount > 0 {
|
||||
opts := issue.NewIssueGetCommentsAndTimelineParams().WithOwner(org).WithRepo(repo).WithIndex(idx).WithPage(&page)
|
||||
if !LastCachedTime.IsZero() {
|
||||
|
||||
@@ -2718,44 +2718,6 @@ func (c *MockGiteaFetchMaintainershipFileCall) DoAndReturn(f func(string, string
|
||||
return c
|
||||
}
|
||||
|
||||
// GetCacheTTL mocks base method.
|
||||
func (m *MockGitea) GetCacheTTL() time.Duration {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetCacheTTL")
|
||||
ret0, _ := ret[0].(time.Duration)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetCacheTTL indicates an expected call of GetCacheTTL.
|
||||
func (mr *MockGiteaMockRecorder) GetCacheTTL() *MockGiteaGetCacheTTLCall {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCacheTTL", reflect.TypeOf((*MockGitea)(nil).GetCacheTTL))
|
||||
return &MockGiteaGetCacheTTLCall{Call: call}
|
||||
}
|
||||
|
||||
// MockGiteaGetCacheTTLCall wrap *gomock.Call
|
||||
type MockGiteaGetCacheTTLCall struct {
|
||||
*gomock.Call
|
||||
}
|
||||
|
||||
// Return rewrite *gomock.Call.Return
|
||||
func (c *MockGiteaGetCacheTTLCall) Return(arg0 time.Duration) *MockGiteaGetCacheTTLCall {
|
||||
c.Call = c.Call.Return(arg0)
|
||||
return c
|
||||
}
|
||||
|
||||
// Do rewrite *gomock.Call.Do
|
||||
func (c *MockGiteaGetCacheTTLCall) Do(f func() time.Duration) *MockGiteaGetCacheTTLCall {
|
||||
c.Call = c.Call.Do(f)
|
||||
return c
|
||||
}
|
||||
|
||||
// DoAndReturn rewrite *gomock.Call.DoAndReturn
|
||||
func (c *MockGiteaGetCacheTTLCall) DoAndReturn(f func() time.Duration) *MockGiteaGetCacheTTLCall {
|
||||
c.Call = c.Call.DoAndReturn(f)
|
||||
return c
|
||||
}
|
||||
|
||||
// GetCommit mocks base method.
|
||||
func (m *MockGitea) GetCommit(org, repo, sha string) (*models.Commit, error) {
|
||||
m.ctrl.T.Helper()
|
||||
@@ -3617,42 +3579,6 @@ func (c *MockGiteaResetTimelineCacheCall) DoAndReturn(f func(string, string, int
|
||||
return c
|
||||
}
|
||||
|
||||
// SetCacheTTL mocks base method.
|
||||
func (m *MockGitea) SetCacheTTL(ttl time.Duration) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "SetCacheTTL", ttl)
|
||||
}
|
||||
|
||||
// SetCacheTTL indicates an expected call of SetCacheTTL.
|
||||
func (mr *MockGiteaMockRecorder) SetCacheTTL(ttl any) *MockGiteaSetCacheTTLCall {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetCacheTTL", reflect.TypeOf((*MockGitea)(nil).SetCacheTTL), ttl)
|
||||
return &MockGiteaSetCacheTTLCall{Call: call}
|
||||
}
|
||||
|
||||
// MockGiteaSetCacheTTLCall wrap *gomock.Call
|
||||
type MockGiteaSetCacheTTLCall struct {
|
||||
*gomock.Call
|
||||
}
|
||||
|
||||
// Return rewrite *gomock.Call.Return
|
||||
func (c *MockGiteaSetCacheTTLCall) Return() *MockGiteaSetCacheTTLCall {
|
||||
c.Call = c.Call.Return()
|
||||
return c
|
||||
}
|
||||
|
||||
// Do rewrite *gomock.Call.Do
|
||||
func (c *MockGiteaSetCacheTTLCall) Do(f func(time.Duration)) *MockGiteaSetCacheTTLCall {
|
||||
c.Call = c.Call.Do(f)
|
||||
return c
|
||||
}
|
||||
|
||||
// DoAndReturn rewrite *gomock.Call.DoAndReturn
|
||||
func (c *MockGiteaSetCacheTTLCall) DoAndReturn(f func(time.Duration)) *MockGiteaSetCacheTTLCall {
|
||||
c.Call = c.Call.DoAndReturn(f)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetCommitStatus mocks base method.
|
||||
func (m *MockGitea) SetCommitStatus(org, repo, hash string, status *models.CommitStatus) (*models.CommitStatus, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
@@ -95,6 +95,7 @@ services:
|
||||
- AMQP_USERNAME=gitea
|
||||
- AMQP_PASSWORD=gitea
|
||||
- SSL_CERT_FILE=/usr/share/pki/trust/anchors/gitea-rabbitmq-ca.crt
|
||||
- AUTOGITS_TIMELINE_CACHE_DISABLE=1
|
||||
volumes:
|
||||
- ./gitea-data:/var/lib/gitea:ro,z
|
||||
- ./workflow-pr/workflow-pr.json:/etc/workflow-pr.json:ro,z
|
||||
|
||||
@@ -139,7 +139,6 @@ index 00000000..473a0f4c
|
||||
|
||||
|
||||
@pytest.mark.t005
|
||||
# @pytest.mark.xfail(reason="TBD troubleshoot")
|
||||
def test_005_any_maintainer_approval_sufficient(maintainer_env, ownerA_client, ownerBB_client):
|
||||
"""
|
||||
Test scenario:
|
||||
@@ -201,7 +200,6 @@ index 00000000..473a0f4c
|
||||
|
||||
|
||||
@pytest.mark.t006
|
||||
@pytest.mark.xfail(reason="tbd flacky in ci")
|
||||
def test_006_maintainer_rejection_removes_other_requests(maintainer_env, ownerA_client, ownerBB_client):
|
||||
"""
|
||||
Test scenario:
|
||||
|
||||
@@ -1249,9 +1249,6 @@ func main() {
|
||||
}
|
||||
|
||||
gitea := common.AllocateGiteaTransport(GiteaUrl)
|
||||
if PollInterval < gitea.GetCacheTTL() {
|
||||
gitea.SetCacheTTL(PollInterval)
|
||||
}
|
||||
|
||||
user, err := gitea.GetCurrentUser()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user