From f8580a1d936eab95f0bf663147c90de28045b373 Mon Sep 17 00:00:00 2001 From: Michael Kriese <michael.kriese@visualon.de> Date: Tue, 16 Mar 2021 11:10:18 +0100 Subject: [PATCH] feat(gitea): filter archived autodiscover repos (#9153) --- .../__snapshots__/gitea-helper.spec.ts.snap | 2 +- .../gitea/__snapshots__/index.spec.ts.snap | 28 +++++++++---------- lib/platform/gitea/gitea-helper.spec.ts | 6 ++-- lib/platform/gitea/gitea-helper.ts | 1 + lib/platform/gitea/index.spec.ts | 4 +-- lib/platform/gitea/index.ts | 5 +++- 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/lib/platform/gitea/__snapshots__/gitea-helper.spec.ts.snap b/lib/platform/gitea/__snapshots__/gitea-helper.spec.ts.snap index f9c896a82a..8e84dba5ae 100644 --- a/lib/platform/gitea/__snapshots__/gitea-helper.spec.ts.snap +++ b/lib/platform/gitea/__snapshots__/gitea-helper.spec.ts.snap @@ -694,7 +694,7 @@ Array [ "user-agent": "https://github.com/renovatebot/renovate", }, "method": "GET", - "url": "https://gitea.renovatebot.com/api/v1/repos/search?uid=13", + "url": "https://gitea.renovatebot.com/api/v1/repos/search?uid=13&archived=false", }, ] `; diff --git a/lib/platform/gitea/__snapshots__/index.spec.ts.snap b/lib/platform/gitea/__snapshots__/index.spec.ts.snap index d455cb8940..45d8f593ea 100644 --- a/lib/platform/gitea/__snapshots__/index.spec.ts.snap +++ b/lib/platform/gitea/__snapshots__/index.spec.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`platform/gitea createPr should use base branch by default 1`] = ` +exports[`platform/gitea/index createPr should use base branch by default 1`] = ` Object { "body": "pr-body", "canMerge": true, @@ -18,7 +18,7 @@ Object { } `; -exports[`platform/gitea createPr should use default branch if requested 1`] = ` +exports[`platform/gitea/index createPr should use default branch if requested 1`] = ` Object { "body": "pr-body", "canMerge": true, @@ -36,7 +36,7 @@ Object { } `; -exports[`platform/gitea getPr should fallback to direct fetching if cache fails 1`] = ` +exports[`platform/gitea/index getPr should fallback to direct fetching if cache fails 1`] = ` Object { "body": "some random pull request", "canMerge": true, @@ -54,7 +54,7 @@ Object { } `; -exports[`platform/gitea getPr should return enriched pull request which exists if open 1`] = ` +exports[`platform/gitea/index getPr should return enriched pull request which exists if open 1`] = ` Object { "body": "some random pull request", "canMerge": true, @@ -72,14 +72,14 @@ Object { } `; -exports[`platform/gitea getPrList should filter list by creator 1`] = ` +exports[`platform/gitea/index getPrList should filter list by creator 1`] = ` Object { "endpoint": "https://gitea.com/api/v1/", "gitAuthor": "Renovate Bot <renovate@example.com>", } `; -exports[`platform/gitea getPrList should filter list by creator 2`] = ` +exports[`platform/gitea/index getPrList should filter list by creator 2`] = ` Array [ Object { "body": "some random pull request", @@ -114,7 +114,7 @@ Array [ ] `; -exports[`platform/gitea getPrList should return list of pull requests 1`] = ` +exports[`platform/gitea/index getPrList should return list of pull requests 1`] = ` Array [ Object { "body": "some random pull request", @@ -149,49 +149,49 @@ Array [ ] `; -exports[`platform/gitea getRepos should return an array of repos 1`] = ` +exports[`platform/gitea/index getRepos should return an array of repos 1`] = ` Array [ "a/b", "c/d", ] `; -exports[`platform/gitea initPlatform() should support custom endpoint 1`] = ` +exports[`platform/gitea/index initPlatform() should support custom endpoint 1`] = ` Object { "endpoint": "https://gitea.renovatebot.com/", "gitAuthor": "Renovate Bot <renovate@example.com>", } `; -exports[`platform/gitea initPlatform() should support default endpoint 1`] = ` +exports[`platform/gitea/index initPlatform() should support default endpoint 1`] = ` Object { "endpoint": "https://gitea.com/api/v1/", "gitAuthor": "Renovate Bot <renovate@example.com>", } `; -exports[`platform/gitea initPlatform() should use username as author name if full name is missing 1`] = ` +exports[`platform/gitea/index initPlatform() should use username as author name if full name is missing 1`] = ` Object { "endpoint": "https://gitea.com/api/v1/", "gitAuthor": "renovate <renovate@example.com>", } `; -exports[`platform/gitea initRepo should fall back to merge method "merge" 1`] = ` +exports[`platform/gitea/index initRepo should fall back to merge method "merge" 1`] = ` Object { "defaultBranch": "master", "isFork": false, } `; -exports[`platform/gitea initRepo should fall back to merge method "rebase-merge" 1`] = ` +exports[`platform/gitea/index initRepo should fall back to merge method "rebase-merge" 1`] = ` Object { "defaultBranch": "master", "isFork": false, } `; -exports[`platform/gitea initRepo should fall back to merge method "squash" 1`] = ` +exports[`platform/gitea/index initRepo should fall back to merge method "squash" 1`] = ` Object { "defaultBranch": "master", "isFork": false, diff --git a/lib/platform/gitea/gitea-helper.spec.ts b/lib/platform/gitea/gitea-helper.spec.ts index 2e74e94955..fc0fdf292c 100644 --- a/lib/platform/gitea/gitea-helper.spec.ts +++ b/lib/platform/gitea/gitea-helper.spec.ts @@ -1,9 +1,10 @@ import * as httpMock from '../../../test/http-mock'; +import { getName } from '../../../test/util'; import { PrState } from '../../types'; import { setBaseUrl } from '../../util/http/gitea'; import * as ght from './gitea-helper'; -describe('platform/gitea/gitea-helper', () => { +describe(getName(__filename), () => { const baseUrl = 'https://gitea.renovatebot.com/api/v1'; const mockCommitHash = '0d9c7726c3d628b7e28af234595cfd20febdbf8e'; @@ -186,7 +187,7 @@ describe('platform/gitea/gitea-helper', () => { it('should construct proper query parameters', async () => { httpMock .scope(baseUrl) - .get('/repos/search?uid=13') + .get('/repos/search?uid=13&archived=false') .reply(200, { ok: true, data: [otherMockRepo], @@ -194,6 +195,7 @@ describe('platform/gitea/gitea-helper', () => { const res = await ght.searchRepos({ uid: 13, + archived: false, }); expect(res).toEqual([otherMockRepo]); expect(httpMock.getTrace()).toMatchSnapshot(); diff --git a/lib/platform/gitea/gitea-helper.ts b/lib/platform/gitea/gitea-helper.ts index 5d07710d2b..f0c9a0b36c 100644 --- a/lib/platform/gitea/gitea-helper.ts +++ b/lib/platform/gitea/gitea-helper.ts @@ -132,6 +132,7 @@ export interface CombinedCommitStatus { export type RepoSearchParams = { uid?: number; + archived?: boolean; }; export type IssueCreateParams = IssueUpdateParams; diff --git a/lib/platform/gitea/index.spec.ts b/lib/platform/gitea/index.spec.ts index 1c9e57ff00..6559c175e8 100644 --- a/lib/platform/gitea/index.spec.ts +++ b/lib/platform/gitea/index.spec.ts @@ -1,5 +1,5 @@ import { BranchStatusConfig, Platform, RepoParams, RepoResult } from '..'; -import { partial } from '../../../test/util'; +import { getName, partial } from '../../../test/util'; import { REPOSITORY_ACCESS_FORBIDDEN, REPOSITORY_ARCHIVED, @@ -20,7 +20,7 @@ import * as ght from './gitea-helper'; */ const GITEA_VERSION = '1.14.0+dev-754-g5d2b7ba63'; -describe('platform/gitea', () => { +describe(getName(__filename), () => { let gitea: Platform; let helper: jest.Mocked<typeof import('./gitea-helper')>; let logger: jest.Mocked<typeof _logger>; diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index 49fd954094..0c6252f7e9 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -314,7 +314,10 @@ const platform: Platform = { async getRepos(): Promise<string[]> { logger.debug('Auto-discovering Gitea repositories'); try { - const repos = await helper.searchRepos({ uid: botUserID }); + const repos = await helper.searchRepos({ + uid: botUserID, + archived: false, + }); return repos.map((r) => r.full_name); } catch (err) { logger.error({ err }, 'Gitea getRepos() error'); -- GitLab