mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 23:16:26 +00:00
fix(github): Disable autoMergeAllowed field for GHE (#12458)
This commit is contained in:
parent
bd71fffa30
commit
d590418111
4 changed files with 60 additions and 8 deletions
|
@ -6998,6 +6998,17 @@ Object {
|
|||
|
||||
exports[`platform/github/index initPlatform() should support custom endpoint 2`] = `
|
||||
Array [
|
||||
Object {
|
||||
"headers": Object {
|
||||
"accept": "application/vnd.github.v3+json",
|
||||
"accept-encoding": "gzip, deflate, br",
|
||||
"authorization": "token 123test",
|
||||
"host": "ghe.renovatebot.com",
|
||||
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
|
||||
},
|
||||
"method": "HEAD",
|
||||
"url": "https://ghe.renovatebot.com/",
|
||||
},
|
||||
Object {
|
||||
"headers": Object {
|
||||
"accept": "application/vnd.github.v3+json",
|
||||
|
@ -7837,6 +7848,17 @@ Array [
|
|||
|
||||
exports[`platform/github/index massageMarkdown(input) returns not-updated pr body for GHE 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"headers": Object {
|
||||
"accept": "application/vnd.github.v3+json",
|
||||
"accept-encoding": "gzip, deflate, br",
|
||||
"authorization": "token 123test",
|
||||
"host": "github.company.com",
|
||||
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
|
||||
},
|
||||
"method": "HEAD",
|
||||
"url": "https://github.company.com/",
|
||||
},
|
||||
Object {
|
||||
"headers": Object {
|
||||
"accept": "application/vnd.github.v3+json",
|
||||
|
@ -7871,7 +7893,6 @@ Array [
|
|||
"name": "$name",
|
||||
"owner": "$owner",
|
||||
},
|
||||
"autoMergeAllowed": null,
|
||||
"defaultBranchRef": Object {
|
||||
"name": null,
|
||||
"target": Object {
|
||||
|
@ -7896,7 +7917,7 @@ Array [
|
|||
"accept": "application/vnd.github.v3+json",
|
||||
"accept-encoding": "gzip, deflate, br",
|
||||
"authorization": "token 123test",
|
||||
"content-length": "395",
|
||||
"content-length": "373",
|
||||
"content-type": "application/json",
|
||||
"host": "github.company.com",
|
||||
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
|
||||
|
|
|
@ -111,6 +111,9 @@ describe('platform/github/index', () => {
|
|||
it('should support custom endpoint', async () => {
|
||||
httpMock
|
||||
.scope('https://ghe.renovatebot.com')
|
||||
.head('/')
|
||||
.reply(200, '', { 'x-github-enterprise-version': '3.0.15' })
|
||||
|
||||
.get('/user')
|
||||
.reply(200, {
|
||||
login: 'renovate-bot',
|
||||
|
@ -2220,6 +2223,8 @@ describe('platform/github/index', () => {
|
|||
it('returns not-updated pr body for GHE', async () => {
|
||||
const scope = httpMock
|
||||
.scope('https://github.company.com')
|
||||
.head('/')
|
||||
.reply(200, '', { 'x-github-enterprise-version': '3.1.7' })
|
||||
.get('/user')
|
||||
.reply(200, {
|
||||
login: 'renovate-bot',
|
||||
|
@ -2407,9 +2412,9 @@ describe('platform/github/index', () => {
|
|||
});
|
||||
it('returns file content in json5 format', async () => {
|
||||
const json5Data = `
|
||||
{
|
||||
{
|
||||
// json5 comment
|
||||
foo: 'bar'
|
||||
foo: 'bar'
|
||||
}
|
||||
`;
|
||||
const scope = httpMock.scope(githubApiHost);
|
||||
|
|
|
@ -3,6 +3,7 @@ import is from '@sindresorhus/is';
|
|||
import delay from 'delay';
|
||||
import JSON5 from 'json5';
|
||||
import { DateTime } from 'luxon';
|
||||
import { valid as semverValid } from 'semver';
|
||||
import { PlatformId } from '../../constants';
|
||||
import {
|
||||
PLATFORM_INTEGRATION_UNAUTHORIZED,
|
||||
|
@ -97,6 +98,19 @@ export async function initPlatform({
|
|||
} else {
|
||||
logger.debug('Using default github endpoint: ' + defaults.endpoint);
|
||||
}
|
||||
|
||||
config.isGhe = URL.parse(defaults.endpoint).host !== 'api.github.com';
|
||||
if (config.isGhe) {
|
||||
const gheHeaderKey = 'x-github-enterprise-version';
|
||||
const gheQueryRes = await githubApi.head('/', { throwHttpErrors: false });
|
||||
const gheHeaders: Record<string, string> = gheQueryRes?.headers || {};
|
||||
const [, gheVersion] =
|
||||
Object.entries(gheHeaders).find(
|
||||
([k]) => k.toLowerCase() === gheHeaderKey
|
||||
) ?? [];
|
||||
config.gheVersion = semverValid(gheVersion) ?? null;
|
||||
}
|
||||
|
||||
let userDetails: UserDetails;
|
||||
let renovateUsername: string;
|
||||
if (username) {
|
||||
|
@ -187,7 +201,13 @@ export async function initRepo({
|
|||
}: RepoParams): Promise<RepoResult> {
|
||||
logger.debug(`initRepo("${repository}")`);
|
||||
// config is used by the platform api itself, not necessary for the app layer to know
|
||||
config = { repository, cloneSubmodules, ignorePrAuthor } as any;
|
||||
config = {
|
||||
repository,
|
||||
cloneSubmodules,
|
||||
ignorePrAuthor,
|
||||
isGhe: config.isGhe,
|
||||
gheVersion: config.gheVersion,
|
||||
} as any;
|
||||
// istanbul ignore if
|
||||
if (endpoint) {
|
||||
// Necessary for Renovate Pro - do not remove
|
||||
|
@ -199,14 +219,19 @@ export async function initRepo({
|
|||
hostType: PlatformId.Github,
|
||||
url: defaults.endpoint,
|
||||
});
|
||||
config.isGhe = URL.parse(defaults.endpoint).host !== 'api.github.com';
|
||||
config.renovateUsername = renovateUsername;
|
||||
[config.repositoryOwner, config.repositoryName] = repository.split('/');
|
||||
let repo: GhRepo;
|
||||
try {
|
||||
let infoQuery = repoInfoQuery;
|
||||
|
||||
if (config.isGhe) {
|
||||
infoQuery = infoQuery.replace(/\n\s*autoMergeAllowed\s*\n/, '\n');
|
||||
}
|
||||
|
||||
const res = await githubApi.requestGraphql<{
|
||||
repository: GhRepo;
|
||||
}>(repoInfoQuery, {
|
||||
}>(infoQuery, {
|
||||
variables: {
|
||||
owner: config.repositoryOwner,
|
||||
name: config.repositoryName,
|
||||
|
@ -1418,7 +1443,7 @@ async function tryPrAutomerge(
|
|||
return;
|
||||
}
|
||||
|
||||
if (!config.autoMergeAllowed) {
|
||||
if (config.autoMergeAllowed === false) {
|
||||
logger.debug(
|
||||
{ prNumber },
|
||||
'GitHub-native automerge: not enabled in repo settings'
|
||||
|
|
|
@ -71,6 +71,7 @@ export interface LocalRepoConfig {
|
|||
repositoryOwner: string;
|
||||
repository: string | null;
|
||||
isGhe: boolean;
|
||||
gheVersion?: string | null;
|
||||
renovateUsername: string;
|
||||
productLinks: any;
|
||||
ignorePrAuthor: boolean;
|
||||
|
|
Loading…
Reference in a new issue