apache / apache/incubator-kie-issues

Unify type of credentials used in githubscm methods

Open
#772 1 comment 0 reactions 2 assignees Claimed by @cimbalek View on GitHub
area:cicd
Dominant language
No language data
Stars
14
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Currently githubscm methods work with either credentials_id or token_credentials_id.

The real difference between the value is that credentials_id is username:password pair, whereas token_credentials_id is just string token. Moreover since GitHub stopped accepting passwords for authentication, in fact the username:password pair is currently username:token - thus the value hold by token_credentials_id is typically contained and accessible in matching credentials_id value.

This task should entail research of all applicable usages in githubscm (and pipelines using it) and evaluation if all can be replaced by credentials_id username:token pair.

It would simplify constructs as:
```
def checkoutIfExists(String repository, String author, String branches, String defaultAuthor, String defaultBranches, boolean mergeTarget = false, def credentials = ['token': 'kie-ci1-token', 'usernamePassword': 'kie-ci']) {
assert credentials['token']
assert credentials['usernamePassword']
def sourceAuthor = author
def sourceRepository = getForkedProjectName(defaultAuthor, repository, sourceAuthor, credentials['token']) ?: repository
// Checks source group and branch (for cases where the branch has been created in the author's forked project)
def repositoryScm = getRepositoryScm(sourceRepository, author, branches, credentials['usernamePassword'])
....

```
Notice the selective passing of correct credentials type to individual method based on how they're implemented.
It should be possible to rewrite the methods expecting token, and instead of:
```
withCredentials([string(credentialsId: credentialsId, variable: 'GITHUB_TOKEN')]) {
```
use
```
withCredentials([usernamePassword(credentialsId: credentialsId, usernameVariable: 'GITHUB_USER', passwordVariable: 'GITHUB_TOKEN')]) {
```
And just not using GITHUB_USER env var if not needed. But would simplify the implementation.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.