diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml deleted file mode 100644 index 9466025d..00000000 --- a/.github/workflows/cla.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: "CLA Assistant" -on: - issue_comment: - types: [created] - pull_request_target: - types: [opened,closed,synchronize] - -jobs: - CLAssistant: - runs-on: ubuntu-latest - steps: - - name: "CLA Assistant" - if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target' - # Beta Release - uses: cla-assistant/github-action@v2.1.3-beta - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # the below token should have repo scope and must be manually added by you in the repository's secret - PERSONAL_ACCESS_TOKEN : ${{ secrets.PERSONAL_ACCESS_TOKEN }} - with: - path-to-signatures: 'signatures/version1/cla.json' - path-to-document: 'https://github.com/cla-assistant/github-action/blob/master/SAPCLA.md' # e.g. a CLA or a DCO document - # branch should not be protected - branch: 'main' - allowlist: user1,bot* - - #below are the optional inputs - If the optional inputs are not given, then default values will be taken - #remote-organization-name: enter the remote organization name where the signatures should be stored (Default is storing the signatures in the same repository) - #remote-repository-name: enter the remote repository name where the signatures should be stored (Default is storing the signatures in the same repository) - #create-file-commit-message: 'For example: Creating file for storing CLA Signatures' - #signed-commit-message: 'For example: $contributorName has signed the CLA in #$pullRequestNo' - #custom-notsigned-prcomment: 'pull request comment with Introductory message to ask new contributors to sign' - #custom-pr-sign-comment: 'The signature to be committed in order to sign the CLA' - #custom-allsigned-prcomment: 'pull request comment when all contributors has signed, defaults to **CLA Assistant Lite bot** All Contributors have signed the CLA.' - #lock-pullrequest-aftermerge: false - if you don't want this bot to automatically lock the pull request after merging (default - true) - #use-dco-flag: true - If you are using DCO instead of CLA diff --git a/SAPCLA.md b/SAPCLA.md deleted file mode 100644 index 3f0d2eb3..00000000 --- a/SAPCLA.md +++ /dev/null @@ -1,66 +0,0 @@ -### SAP Individual Contributor License Agreement - -Thank you for your interest in contributing to open source software projects (“Projects”) made available by SAP SE or its affiliates (“SAP”). This Individual Contributor License Agreement (“Agreement”) sets out the terms governing any source code, object code, bug fixes, configuration changes, tools, specifications, documentation, data, materials, feedback, information or other works of authorship that you submit or have submitted, in any form and in any manner, to SAP in respect of any of the Projects (collectively “Contributions”). If you have any questions respecting this Agreement, please contact opensource@sap.com. - - -You agree that the following terms apply to all of your past, present and future Contributions. Except for the licenses granted in this Agreement, you retain all of your right, title and interest in and to your Contributions. - - -**Copyright License.** You hereby grant, and agree to grant, to SAP a non-exclusive, perpetual, irrevocable, worldwide, fully-paid, royalty-free, transferable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute your Contributions and such derivative works, with the right to sublicense the foregoing rights through multiple tiers of sublicensees. - - -**Patent License.** You hereby grant, and agree to grant, to SAP a non-exclusive, perpetual, irrevocable, -worldwide, fully-paid, royalty-free, transferable patent license to make, have made, use, offer to sell, sell, -import, and otherwise transfer your Contributions, where such license applies only to those patent claims -licensable by you that are necessarily infringed by your Contributions alone or by combination of your -Contributions with the Project to which such Contributions were submitted, with the right to sublicense the -foregoing rights through multiple tiers of sublicensees. - - -**Moral Rights.** To the fullest extent permitted under applicable law, you hereby waive, and agree not to -assert, all of your “moral rights” in or relating to your Contributions for the benefit of SAP, its assigns, and -their respective direct and indirect sublicensees. - - -**Third Party Content/Rights.** If your Contribution includes or is based on any source code, object code, bug -fixes, configuration changes, tools, specifications, documentation, data, materials, feedback, information or -other works of authorship that were not authored by you (“Third Party Content”) or if you are aware of any -third party intellectual property or proprietary rights associated with your Contribution (“Third Party Rights”), -then you agree to include with the submission of your Contribution full details respecting such Third Party -Content and Third Party Rights, including, without limitation, identification of which aspects of your -Contribution contain Third Party Content or are associated with Third Party Rights, the owner/author of the -Third Party Content and Third Party Rights, where you obtained the Third Party Content, and any applicable -third party license terms or restrictions respecting the Third Party Content and Third Party Rights. For greater -certainty, the foregoing obligations respecting the identification of Third Party Content and Third Party Rights -do not apply to any portion of a Project that is incorporated into your Contribution to that same Project. - - -**Representations.** You represent that, other than the Third Party Content and Third Party Rights identified by -you in accordance with this Agreement, you are the sole author of your Contributions and are legally entitled -to grant the foregoing licenses and waivers in respect of your Contributions. If your Contributions were -created in the course of your employment with your past or present employer(s), you represent that such -employer(s) has authorized you to make your Contributions on behalf of such employer(s) or such employer -(s) has waived all of their right, title or interest in or to your Contributions. - - -**Disclaimer.** To the fullest extent permitted under applicable law, your Contributions are provided on an "asis" -basis, without any warranties or conditions, express or implied, including, without limitation, any implied -warranties or conditions of non-infringement, merchantability or fitness for a particular purpose. You are not -required to provide support for your Contributions, except to the extent you desire to provide support. - - -**No Obligation.** You acknowledge that SAP is under no obligation to use or incorporate your Contributions -into any of the Projects. The decision to use or incorporate your Contributions into any of the Projects will be -made at the sole discretion of SAP or its authorized delegates .. - - -**Disputes.** This Agreement shall be governed by and construed in accordance with the laws of the State of -New York, United States of America, without giving effect to its principles or rules regarding conflicts of laws, -other than such principles directing application of New York law. The parties hereby submit to venue in, and -jurisdiction of the courts located in New York, New York for purposes relating to this Agreement. In the event -that any of the provisions of this Agreement shall be held by a court or other tribunal of competent jurisdiction -to be unenforceable, the remaining portions hereof shall remain in full force and effect. - - -**Assignment.** You agree that SAP may assign this Agreement, and all of its rights, obligations and licenses -hereunder. diff --git a/dist/index.js b/dist/index.js index 92bc9c12..0ca7390c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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`); @@ -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, @@ -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, @@ -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); @@ -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; +} /***/ }), diff --git a/src/octokit.ts b/src/octokit.ts index 2b9a17ba..bb94dfd6 100644 --- a/src/octokit.ts +++ b/src/octokit.ts @@ -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( diff --git a/src/persistence/persistence.ts b/src/persistence/persistence.ts index 5b3c31af..ecbee079 100644 --- a/src/persistence/persistence.ts +++ b/src/persistence/persistence.ts @@ -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 { - const octokitInstance: InstanceType = getPATOctokit() + const octokitInstance: InstanceType = + isRemoteRepoOrOrgConfigured() ? getPATOctokit() : getDefaultOctokitClient() + const result = await octokitInstance.repos.getContent({ owner: input.getRemoteOrgName() || context.repo.owner, repo: input.getRemoteRepoName() || context.repo.repo, @@ -18,7 +20,9 @@ export async function getFileContent(): Promise { } export async function createFile(contentBinary): Promise { - const octokitInstance: InstanceType = getPATOctokit() + const octokitInstance: InstanceType = + isRemoteRepoOrOrgConfigured() ? getPATOctokit() : getDefaultOctokitClient() + return octokitInstance.repos.createOrUpdateFileContents({ owner: input.getRemoteOrgName() || context.repo.owner, repo: input.getRemoteRepoName() || context.repo.repo, @@ -32,7 +36,9 @@ export async function createFile(contentBinary): Promise { } export async function updateFile(sha: string, claFileContent, reactedCommitters: ReactedCommitterMap): Promise { - const octokitInstance: InstanceType = getPATOctokit() + + const octokitInstance: InstanceType = + isRemoteRepoOrOrgConfigured() ? getPATOctokit() : getDefaultOctokitClient() const pullRequestNo = context.issue.number claFileContent?.signedContributors.push(...reactedCommitters.newSigned) let contentString = JSON.stringify(claFileContent, null, 2) @@ -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 +}