Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ibakshay authored Feb 9, 2023
2 parents f003d1b + 724af84 commit 7467a39
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 122 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/cla.yml

This file was deleted.

66 changes: 0 additions & 66 deletions SAPCLA.md

This file was deleted.

26 changes: 16 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPersonalAccessTokenPresent = exports.getPATOctokit = exports.octokit = void 0;
exports.isPersonalAccessTokenPresent = exports.getPATOctokit = exports.getDefaultOctokitClient = exports.octokit = void 0;
const github_1 = __webpack_require__(469);
const core = __importStar(__webpack_require__(470));
const githubActionsDefaultToken = process.env.GITHUB_TOKEN;
const personalAccessToken = process.env.PERSONAL_ACCESS_TOKEN;
exports.octokit = (0, github_1.getOctokit)(githubActionsDefaultToken);
/*export async function getOctokitClient() {
if (isPersonalAccessTokenPresent()) {
return getPATOctokit()
}
return octokit
}*/
function getDefaultOctokitClient() {
return (0, github_1.getOctokit)(githubActionsDefaultToken);
}
exports.getDefaultOctokitClient = getDefaultOctokitClient;
function getPATOctokit() {
if (!isPersonalAccessTokenPresent()) {
core.setFailed(`Please add a personal access token as an environment variable for writing signatures in a remote repository/organization as mentioned in the README.md file`);
Expand Down Expand Up @@ -1876,7 +1874,7 @@ const octokit_1 = __webpack_require__(28);
const input = __importStar(__webpack_require__(555));
function getFileContent() {
return __awaiter(this, void 0, void 0, function* () {
const octokitInstance = (0, octokit_1.getPATOctokit)();
const octokitInstance = isRemoteRepoOrOrgConfigured() ? (0, octokit_1.getPATOctokit)() : (0, octokit_1.getDefaultOctokitClient)();
const result = yield octokitInstance.repos.getContent({
owner: input.getRemoteOrgName() || github_1.context.repo.owner,
repo: input.getRemoteRepoName() || github_1.context.repo.repo,
Expand All @@ -1889,7 +1887,7 @@ function getFileContent() {
exports.getFileContent = getFileContent;
function createFile(contentBinary) {
return __awaiter(this, void 0, void 0, function* () {
const octokitInstance = (0, octokit_1.getPATOctokit)();
const octokitInstance = isRemoteRepoOrOrgConfigured() ? (0, octokit_1.getPATOctokit)() : (0, octokit_1.getDefaultOctokitClient)();
return octokitInstance.repos.createOrUpdateFileContents({
owner: input.getRemoteOrgName() || github_1.context.repo.owner,
repo: input.getRemoteRepoName() || github_1.context.repo.repo,
Expand All @@ -1904,7 +1902,7 @@ function createFile(contentBinary) {
exports.createFile = createFile;
function updateFile(sha, claFileContent, reactedCommitters) {
return __awaiter(this, void 0, void 0, function* () {
const octokitInstance = (0, octokit_1.getPATOctokit)();
const octokitInstance = isRemoteRepoOrOrgConfigured() ? (0, octokit_1.getPATOctokit)() : (0, octokit_1.getDefaultOctokitClient)();
const pullRequestNo = github_1.context.issue.number;
claFileContent === null || claFileContent === void 0 ? void 0 : claFileContent.signedContributors.push(...reactedCommitters.newSigned);
let contentString = JSON.stringify(claFileContent, null, 2);
Expand All @@ -1925,6 +1923,14 @@ function updateFile(sha, claFileContent, reactedCommitters) {
});
}
exports.updateFile = updateFile;
function isRemoteRepoOrOrgConfigured() {
let isRemoteRepoOrOrgConfigured = false;
if ((input === null || input === void 0 ? void 0 : input.getRemoteRepoName()) || input.getRemoteOrgName()) {
isRemoteRepoOrOrgConfigured = true;
return isRemoteRepoOrOrgConfigured;
}
return isRemoteRepoOrOrgConfigured;
}


/***/ }),
Expand Down
9 changes: 3 additions & 6 deletions src/octokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ const personalAccessToken = process.env.PERSONAL_ACCESS_TOKEN as string

export const octokit = getOctokit(githubActionsDefaultToken as string)

/*export async function getOctokitClient() {
if (isPersonalAccessTokenPresent()) {
return getPATOctokit()
}
return octokit
}*/
export function getDefaultOctokitClient() {
return getOctokit(githubActionsDefaultToken as string)
}
export function getPATOctokit() {
if (!isPersonalAccessTokenPresent()) {
core.setFailed(
Expand Down
23 changes: 19 additions & 4 deletions src/persistence/persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { context } from '@actions/github'

import { ReactedCommitterMap } from '../interfaces'
import { GitHub } from '@actions/github/lib/utils'
import { getPATOctokit } from '../octokit'
import { getDefaultOctokitClient, getPATOctokit } from '../octokit'

import * as input from '../shared/getInputs'

export async function getFileContent(): Promise<any> {
const octokitInstance: InstanceType<typeof GitHub> = getPATOctokit()
const octokitInstance: InstanceType<typeof GitHub> =
isRemoteRepoOrOrgConfigured() ? getPATOctokit() : getDefaultOctokitClient()

const result = await octokitInstance.repos.getContent({
owner: input.getRemoteOrgName() || context.repo.owner,
repo: input.getRemoteRepoName() || context.repo.repo,
Expand All @@ -18,7 +20,9 @@ export async function getFileContent(): Promise<any> {
}

export async function createFile(contentBinary): Promise<any> {
const octokitInstance: InstanceType<typeof GitHub> = getPATOctokit()
const octokitInstance: InstanceType<typeof GitHub> =
isRemoteRepoOrOrgConfigured() ? getPATOctokit() : getDefaultOctokitClient()

return octokitInstance.repos.createOrUpdateFileContents({
owner: input.getRemoteOrgName() || context.repo.owner,
repo: input.getRemoteRepoName() || context.repo.repo,
Expand All @@ -32,7 +36,9 @@ export async function createFile(contentBinary): Promise<any> {
}

export async function updateFile(sha: string, claFileContent, reactedCommitters: ReactedCommitterMap): Promise<any> {
const octokitInstance: InstanceType<typeof GitHub> = getPATOctokit()

const octokitInstance: InstanceType<typeof GitHub> =
isRemoteRepoOrOrgConfigured() ? getPATOctokit() : getDefaultOctokitClient()
const pullRequestNo = context.issue.number
claFileContent?.signedContributors.push(...reactedCommitters.newSigned)
let contentString = JSON.stringify(claFileContent, null, 2)
Expand All @@ -54,3 +60,12 @@ export async function updateFile(sha: string, claFileContent, reactedCommitters:
branch: input.getBranch()
})
}

function isRemoteRepoOrOrgConfigured(): boolean {
let isRemoteRepoOrOrgConfigured = false
if (input?.getRemoteRepoName() || input.getRemoteOrgName()) {
isRemoteRepoOrOrgConfigured = true
return isRemoteRepoOrOrgConfigured
}
return isRemoteRepoOrOrgConfigured
}

0 comments on commit 7467a39

Please sign in to comment.