renovatebot / renovate

Home of the Renovate CLI: Cross-platform Dependency Automation by Mend.io
https://mend.io/renovate
GNU Affero General Public License v3.0
17.3k stars 2.26k forks source link

[GitHub] enable `platformCommit` when we detect an app token #29115

Closed viceice closed 5 days ago

viceice commented 4 months ago

Describe the proposed change(s).

Change platformCommit to enum like with values enabled, auto and disabled. Default to auto. Set to enabled when it's auto and we detect an github app token. i think they start with ghs_.

https://github.com/renovatebot/renovate/blob/66de0465e944f55669d5822cea6a2d459a6e5ed6/lib/util/check-token.ts#L67-L69

rarkins commented 4 months ago

Added breaking tag, let's do it for v38

RahulGautamSingh commented 4 months ago

Is it necessary to do it via token or can we just enabled it when platform is GIthubApp?

When we perform initPlatform we use the token to check whether the platform is a GithubApp and store this information locally in the platformConfig object using isGhApp boolean field. We can reuse this value.

https://github.com/renovatebot/renovate/blob/f8f518493dad03c26facac4f110b4e553b09b99e/lib/modules/platform/github/index.ts#L143-L144

rarkins commented 4 months ago

So will the worker keep platformCommit=auto for the whole run? Where would the logic lie?

RahulGautamSingh commented 4 months ago

We only use this option for Github so we can keep the logic in platform/github/scm, so that might not be an issue even if it's not ideal.

From https://github.com/renovatebot/renovate/blob/f8f518493dad03c26facac4f110b4e553b09b99e/lib/modules/platform/github/scm.ts#L10-L13

To

export class GithubScm extends DefaultGitScm {
  override commitAndPush(
    commitConfig: CommitFilesConfig,
  ): Promise<LongCommitSha | null> {
    let platformCommit = commitConfig.platformCommit;
    if (platformCommit === 'auto' && isGHApp()) {
      platformCommit = 'enabled';
    }

    return commitConfig.platformCommit === 'enabled'
      ? commitFiles(commitConfig)
      : git.commitFiles(commitConfig);
  }
}

The isGhApp fn will reside in platform/github/index

export function isGHApp(): boolean {
  return !!platformConfig.isGHApp;
}
RahulGautamSingh commented 4 months ago

We can also move this logic to the renovateRepository fn. Around here: https://github.com/renovatebot/renovate/blob/f8f518493dad03c26facac4f110b4e553b09b99e/lib/workers/repository/index.ts#L75-L78

This way platformCommit stays changed.

rarkins commented 4 months ago

Keeping the logic in platform sounds better