Compare commits
1 Commits
ci-experim
...
fix/gitea-
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
61bcd5caf4 |
@@ -221,11 +221,14 @@ 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 {
|
||||
@@ -240,10 +243,19 @@ 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)
|
||||
}
|
||||
@@ -868,8 +880,8 @@ func (gitea *GiteaTransport) GetTimeline(org, repo string, idx int64) ([]*models
|
||||
LastCachedTime = TimelineCache.data[0].Updated
|
||||
}
|
||||
|
||||
// cache data for 5 seconds
|
||||
if TimelineCache.lastCheck.Add(time.Second*5).Compare(time.Now()) > 0 {
|
||||
// cache data
|
||||
if TimelineCache.lastCheck.Add(gitea.cacheTTL).Compare(time.Now()) > 0 {
|
||||
giteaTimelineCacheMutex.RUnlock()
|
||||
return TimelineCache.data, nil
|
||||
}
|
||||
|
||||
@@ -2718,6 +2718,44 @@ 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()
|
||||
@@ -3579,6 +3617,42 @@ 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()
|
||||
|
||||
@@ -1249,6 +1249,9 @@ 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