Best JavaScript code snippet using qawolf
checkWipDraftPRSpec.js
Source:checkWipDraftPRSpec.js
1// Copyright 2020 The Oppia Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14require('dotenv').config();15const github = require('@actions/github');16const core = require('@actions/core');17const checkWipDraftPRModule = require(18 '../actions/src/pull_requests/checkWipDraftPR');19const pullRequestEditedPayload = require('../fixtures/pullRequest.edited.json');20const dispatcher = require('../actions/src/dispatcher');21describe("Oppiabot's", () => {22 /**23 * @type {import('@actions/github').GitHub} octokit24 */25 let octokit;26 beforeEach(async () => {27 github.context.eventName = 'pull_request';28 github.context.payload = pullRequestEditedPayload;29 github.context.pull_request = pullRequestEditedPayload.pull_request;30 octokit = {31 issues: {32 createComment: jasmine.createSpy('createComment').and.resolveTo({}),33 addAssignees: jasmine.createSpy('addAssignees').and.resolveTo({}),34 },35 };36 spyOn(core, 'getInput').and.returnValue('sample-token');37 spyOnProperty(github.context, 'repo').and.returnValue({38 owner: pullRequestEditedPayload.repository.owner.login,39 repo: pullRequestEditedPayload.repository.name,40 });41 // Mock GitHub API.42 Object.setPrototypeOf(github.GitHub, function () {43 return octokit;44 });45 spyOn(checkWipDraftPRModule, 'checkWIP').and.callThrough();46 });47 describe('WIP PRs without skip prefix', () => {48 beforeEach(async () => {49 octokit.git = {50 getCommit: jasmine.createSpy('getCommit').and.resolveTo({51 data: {52 message: 'commit without skip prefix',53 },54 }),55 };56 await dispatcher.dispatch('pull_request', 'edited');57 });58 it('calls checkWIP function', () => {59 expect(checkWipDraftPRModule.checkWIP).toHaveBeenCalled();60 });61 it('calls checkWIP once', () => {62 expect(checkWipDraftPRModule.checkWIP).toHaveBeenCalledTimes(1);63 });64 it('calls get commit', () => {65 expect(octokit.git.getCommit).toHaveBeenCalled();66 expect(octokit.git.getCommit).toHaveBeenCalledTimes(1);67 expect(octokit.git.getCommit).toHaveBeenCalledWith({68 owner: pullRequestEditedPayload.repository.owner.login,69 repo: pullRequestEditedPayload.repository.name,70 commit_sha: pullRequestEditedPayload.pull_request.head.sha,71 });72 });73 it('assigns PR author', () => {74 expect(octokit.issues.addAssignees).toHaveBeenCalled();75 const params = {76 repo: pullRequestEditedPayload.repository.name,77 owner: pullRequestEditedPayload.repository.owner.login,78 issue_number: pullRequestEditedPayload.pull_request.number,79 assignees: ['testuser7777'],80 };81 expect(octokit.issues.addAssignees).toHaveBeenCalledWith(params);82 });83 it('creates comment for WIP PRs', () => {84 expect(octokit.issues.createComment).toHaveBeenCalled();85 expect(octokit.issues.createComment).toHaveBeenCalledTimes(1);86 // Comment on Pull Request.87 const link = 'here'.link(88 'https://github.com/oppia/oppia/wiki/Contributing-code-to-Oppia' +89 '#wip--draft-pull-requests'90 );91 const author = pullRequestEditedPayload.pull_request.user.login;92 const commentBody =93 'Hi @' +94 author +95 ', when creating WIP/Draft PRs, ensure that ' +96 'your commit messages are prefixed with **[ci skip]** or ' +97 '**[skip ci]** to prevent CI checks from running. ' +98 'You can learn more about it ' +99 link +100 '.';101 expect(octokit.issues.createComment).toHaveBeenCalledWith({102 issue_number: pullRequestEditedPayload.pull_request.number,103 owner: pullRequestEditedPayload.repository.owner.login,104 repo: pullRequestEditedPayload.repository.name,105 body: commentBody,106 });107 });108 });109 describe('WIP PRs with skip prefix', () => {110 beforeEach(async () => {111 octokit.git = {112 getCommit: jasmine.createSpy('getCommit').and.resolveTo({113 data: {114 message: '[ci skip] commit with skip prefix',115 },116 }),117 };118 await dispatcher.dispatch('pull_request_target', 'edited');119 });120 it('calls checkWIP function', () => {121 expect(checkWipDraftPRModule.checkWIP).toHaveBeenCalled();122 });123 it('calls checkWIP once', () => {124 expect(checkWipDraftPRModule.checkWIP).toHaveBeenCalledTimes(1);125 });126 it('calls get commit', () => {127 expect(octokit.git.getCommit).toHaveBeenCalled();128 expect(octokit.git.getCommit).toHaveBeenCalledTimes(1);129 expect(octokit.git.getCommit).toHaveBeenCalledWith({130 owner: pullRequestEditedPayload.repository.owner.login,131 repo: pullRequestEditedPayload.repository.name,132 commit_sha: pullRequestEditedPayload.pull_request.head.sha,133 });134 });135 it('does not assign PR author', () => {136 expect(octokit.issues.addAssignees).not.toHaveBeenCalled();137 });138 it('does not create comment for WIP PRs', () => {139 expect(octokit.issues.createComment).not.toHaveBeenCalled();140 });141 });142 describe('Checks when PR is opened or reopened', () => {143 it('should check when PR is opened', async () => {144 octokit.git = {145 getCommit: jasmine.createSpy('getCommit').and.resolveTo({146 data: {147 message: 'changes',148 },149 }),150 };151 // Trigger pull_request.opened event.152 pullRequestEditedPayload.action = 'opened';153 await dispatcher.dispatch('pull_request_target', 'opened');154 expect(checkWipDraftPRModule.checkWIP).toHaveBeenCalled();155 expect(octokit.git.getCommit).toHaveBeenCalled();156 expect(octokit.issues.addAssignees).toHaveBeenCalled();157 expect(octokit.issues.addAssignees).toHaveBeenCalledTimes(1);158 expect(octokit.issues.createComment).toHaveBeenCalled();159 expect(octokit.issues.createComment).toHaveBeenCalledTimes(1);160 });161 it('should check when PR is reopened', async () => {162 octokit.git = {163 getCommit: jasmine.createSpy('getCommit').and.resolveTo({164 data: {165 message: 'commit without skip prefix',166 },167 }),168 };169 // Trigger pull_request.opened event.170 pullRequestEditedPayload.action = 'reopened';171 await dispatcher.dispatch('pull_request_target', 'reopened');172 expect(checkWipDraftPRModule.checkWIP).toHaveBeenCalled();173 expect(octokit.git.getCommit).toHaveBeenCalled();174 expect(octokit.issues.addAssignees).toHaveBeenCalled();175 expect(octokit.issues.addAssignees).toHaveBeenCalledTimes(1);176 expect(octokit.issues.createComment).toHaveBeenCalled();177 expect(octokit.issues.createComment).toHaveBeenCalledTimes(1);178 });179 });180 describe('Draft PRs', () => {181 beforeEach(async () => {182 octokit.git = {183 getCommit: jasmine.createSpy('getCommit').and.resolveTo({184 data: {185 message: 'commit without skip prefix',186 },187 }),188 };189 // Receive a draft payload and remove WIP from title.190 pullRequestEditedPayload.pull_request.draft = true;191 pullRequestEditedPayload.pull_request.title = 'Testing Draft';192 await dispatcher.dispatch('pull_request_target', 'opened');193 });194 it('calls checkWIP function', () => {195 expect(checkWipDraftPRModule.checkWIP).toHaveBeenCalled();196 });197 it('calls get commit', () => {198 expect(octokit.git.getCommit).toHaveBeenCalled();199 expect(octokit.git.getCommit).toHaveBeenCalledTimes(1);200 expect(octokit.git.getCommit).toHaveBeenCalledWith({201 owner: pullRequestEditedPayload.repository.owner.login,202 repo: pullRequestEditedPayload.repository.name,203 commit_sha: pullRequestEditedPayload.pull_request.head.sha,204 });205 });206 it('calls checkWIP once', () => {207 expect(checkWipDraftPRModule.checkWIP).toHaveBeenCalledTimes(1);208 });209 it('assigns PR author', () => {210 expect(octokit.issues.addAssignees).toHaveBeenCalled();211 const params = {212 repo: pullRequestEditedPayload.repository.name,213 owner: pullRequestEditedPayload.repository.owner.login,214 issue_number: pullRequestEditedPayload.pull_request.number,215 assignees: ['testuser7777'],216 };217 expect(octokit.issues.addAssignees).toHaveBeenCalledWith(params);218 });219 it('creates comment for draft PRs', () => {220 expect(octokit.issues.createComment).toHaveBeenCalled();221 expect(octokit.issues.createComment).toHaveBeenCalledTimes(1);222 const link = 'here'.link(223 'https://github.com/oppia/oppia/wiki/Contributing-code-to-Oppia' +224 '#wip--draft-pull-requests'225 );226 const author = pullRequestEditedPayload.pull_request.user.login;227 const commentBody =228 'Hi @' +229 author +230 ', when creating WIP/Draft PRs, ensure that ' +231 'your commit messages are prefixed with **[ci skip]** or ' +232 '**[skip ci]** to prevent CI checks from running. ' +233 'You can learn more about it ' +234 link +235 '.';236 expect(octokit.issues.createComment).toHaveBeenCalledWith({237 issue_number: pullRequestEditedPayload.pull_request.number,238 owner: pullRequestEditedPayload.repository.owner.login,239 repo: pullRequestEditedPayload.repository.name,240 body: commentBody,241 });242 });243 });244 describe('Draft PRs with skip prefix', () => {245 beforeEach(async () => {246 octokit.git = {247 getCommit: jasmine.createSpy('getCommit').and.resolveTo({248 data: {249 message: '[skip ci] commit with skip prefix',250 },251 }),252 };253 // Receive a draft payload and remove WIP from title.254 pullRequestEditedPayload.pull_request.draft = true;255 pullRequestEditedPayload.pull_request.title = 'Testing Draft';256 await dispatcher.dispatch('pull_request_target', 'opened');257 });258 it('calls checkWIP function', () => {259 expect(checkWipDraftPRModule.checkWIP).toHaveBeenCalled();260 });261 it('calls checkWIP once', () => {262 expect(checkWipDraftPRModule.checkWIP).toHaveBeenCalledTimes(1);263 });264 it('calls get commit', () => {265 expect(octokit.git.getCommit).toHaveBeenCalled();266 expect(octokit.git.getCommit).toHaveBeenCalledTimes(1);267 expect(octokit.git.getCommit).toHaveBeenCalledWith({268 owner: pullRequestEditedPayload.repository.owner.login,269 repo: pullRequestEditedPayload.repository.name,270 commit_sha: pullRequestEditedPayload.pull_request.head.sha,271 });272 });273 it('does not assign PR author', () => {274 expect(octokit.issues.addAssignees).not.toHaveBeenCalled();275 });276 it('does not create comment for draft PRs', () => {277 expect(octokit.issues.createComment).not.toHaveBeenCalled();278 });279 });280 describe('Neither Draft nor WIP PRs', () => {281 beforeEach(async () => {282 octokit.git = {283 getCommit: jasmine.createSpy('getCommit').and.resolveTo({284 data: {285 message: '[skip ci] commit with skip prefix',286 },287 }),288 };289 // Receive a neither draft nor WIP payload.290 pullRequestEditedPayload.pull_request.draft = false;291 pullRequestEditedPayload.pull_request.title = 'Testing';292 await dispatcher.dispatch('pull_request_target', 'opened');293 });294 it('calls checkWIP function', () => {295 expect(checkWipDraftPRModule.checkWIP).toHaveBeenCalled();296 });297 it('does not call get commit', () => {298 expect(octokit.git.getCommit).not.toHaveBeenCalled();299 });300 it('does not assign PR author', () => {301 expect(octokit.issues.addAssignees).not.toHaveBeenCalled();302 });303 it('does not create a comment', () => {304 expect(octokit.issues.createComment).not.toHaveBeenCalled();305 });306 });...
commit-and-push.ts
Source:commit-and-push.ts
1// Copyright 2020 Google LLC2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14/* eslint-disable node/no-unsupported-features/node-builtins */15import * as assert from 'assert';16import {describe, it, before, afterEach} from 'mocha';17import {octokit, setup} from './util';18import * as sinon from 'sinon';19import {GetResponseTypeFromEndpointMethod} from '@octokit/types';20import * as handler from '../src/github/commit-and-push';21import {Changes, FileData, TreeObject, RepoDomain} from '../src/types';22type GetCommitResponse = GetResponseTypeFromEndpointMethod<23 typeof octokit.git.getCommit24>;25type CreateTreeResponse = GetResponseTypeFromEndpointMethod<26 typeof octokit.git.createTree27>;28type CreateCommitResponse = GetResponseTypeFromEndpointMethod<29 typeof octokit.git.createCommit30>;31before(() => {32 setup();33});34describe('Push', () => {35 const sandbox = sinon.createSandbox();36 const origin: RepoDomain = {37 owner: 'Foo',38 repo: 'Bar',39 };40 const sha = 'asdf1234';41 afterEach(() => {42 sandbox.restore();43 });44 it('GitHub tree objects that are generated correctly for text files in a sub-directory', () => {45 const changes: Changes = new Map();46 changes.set('a/foo.txt', new FileData('Foo content'));47 assert.deepStrictEqual(handler.generateTreeObjects(changes), [48 {49 path: 'a/foo.txt',50 mode: '100644',51 type: 'blob',52 content: 'Foo content',53 },54 ]);55 });56 it('has objects that are generated correctly for text files that are deleted', () => {57 const changes: Changes = new Map();58 changes.set('b/bar.txt', new FileData(null));59 assert.deepStrictEqual(handler.generateTreeObjects(changes), [60 {61 path: 'b/bar.txt',62 mode: '100644',63 type: 'blob',64 sha: null,65 },66 ]);67 });68 it('has objects that are generated correctly for deleted exe files', () => {69 const changes: Changes = new Map();70 changes.set('baz.exe', new FileData(null, '100755'));71 assert.deepStrictEqual(handler.generateTreeObjects(changes), [72 {73 path: 'baz.exe',74 mode: '100755',75 type: 'blob',76 sha: null,77 },78 ]);79 });80 it('has objects that are generated correctly for empty text files', () => {81 const changes: Changes = new Map();82 changes.set('empty.txt', new FileData(''));83 assert.deepStrictEqual(handler.generateTreeObjects(changes), [84 {85 path: 'empty.txt',86 mode: '100644',87 type: 'blob',88 content: '',89 },90 ]);91 });92 it('Calls octokit functions with correct params', async () => {93 const tree: TreeObject[] = [94 {95 path: 'a/foo.txt',96 mode: '100644',97 type: 'blob',98 content: 'Foo content',99 },100 {101 path: 'b/bar.txt',102 mode: '100644',103 type: 'blob',104 sha: null,105 },106 {107 path: 'baz.exe',108 mode: '100755',109 type: 'blob',110 sha: null,111 },112 {113 path: 'empty.txt',114 mode: '100644',115 type: 'blob',116 content: '',117 },118 ];119 const commitResponseData = await import(120 './fixtures/get-commit-response.json'121 );122 const createTreeResponseData = await import(123 './fixtures/create-tree-response.json'124 );125 const getCommitResponse = {126 headers: {},127 status: 200,128 url: 'http://fake-url.com',129 data: commitResponseData,130 } as unknown as GetCommitResponse;131 const createTreeResponse = {132 headers: {},133 status: 201,134 url: 'http://fake-url.com',135 data: createTreeResponseData,136 } as unknown as CreateTreeResponse;137 // setup138 const stubGetCommit = sandbox139 .stub(octokit.git, 'getCommit')140 .resolves(getCommitResponse);141 const stubCreateTree = sandbox142 .stub(octokit.git, 'createTree')143 .resolves(createTreeResponse);144 // tests145 const treeSha = await handler.createTree(octokit, origin, sha, tree);146 sandbox.assert.calledOnceWithExactly(stubGetCommit, {147 owner: origin.owner,148 repo: origin.repo,149 commit_sha: sha,150 });151 sandbox.assert.calledWithExactly(stubCreateTree, {152 owner: origin.owner,153 repo: origin.repo,154 tree,155 base_tree: getCommitResponse.data.tree.sha,156 });157 assert.strictEqual(treeSha, createTreeResponse.data.sha);158 });159});160describe('Commit', () => {161 const sandbox = sinon.createSandbox();162 afterEach(() => {163 sandbox.restore();164 });165 const origin: RepoDomain = {166 owner: 'Foo',167 repo: 'Bar',168 };169 const treeSha = 'TREE-asfd1234';170 const head = 'head-asdf1234';171 const message = 'Hello world';172 it('Invokes octokit function called with correct values', async () => {173 // setup174 const createCommitResponseData = await import(175 './fixtures/create-commit-response.json'176 );177 const createCommitResponse = {178 headers: {},179 status: 201,180 url: 'http://fake-url.com',181 data: createCommitResponseData,182 } as unknown as CreateCommitResponse;183 const stubCreateCommit = sandbox184 .stub(octokit.git, 'createCommit')185 .resolves(createCommitResponse);186 // tests187 const sha = await handler.createCommit(188 octokit,189 origin,190 head,191 treeSha,192 message193 );194 assert.strictEqual(sha, createCommitResponse.data.sha);195 sandbox.assert.calledOnceWithExactly(stubCreateCommit, {196 owner: origin.owner,197 repo: origin.repo,198 message,199 tree: treeSha,200 parents: [head],201 });202 });203});204describe('Update branch reference', () => {205 const sandbox = sinon.createSandbox();206 afterEach(() => {207 sandbox.restore();208 });209 const origin: RepoDomain = {210 owner: 'Foo',211 repo: 'Bar',212 };213 const sha = 'asdf1234';214 it('Invokes octokit function called with correct values', async () => {215 // setup216 const stubUpdateRef = sandbox.stub(octokit.git, 'updateRef');217 // tests218 await handler.updateRef(219 octokit,220 {branch: 'test-branch-name', ...origin},221 sha,222 false223 );224 sandbox.assert.calledOnceWithExactly(stubUpdateRef, {225 owner: origin.owner,226 repo: origin.repo,227 sha,228 ref: 'heads/test-branch-name',229 force: false,230 });231 });232});233describe('Commit and push function', async () => {234 const sandbox = sinon.createSandbox();235 const oldHeadSha = 'OLD-head-Sha-asdf1234';236 const changes: Changes = new Map();237 const origin: RepoDomain = {238 owner: 'Foo',239 repo: 'Bar',240 };241 const branchName = 'test-branch-name';242 const message = 'Hello world';243 const commitResponseData = await import(244 './fixtures/get-commit-response.json'245 );246 const createTreeResponseData = await import(247 './fixtures/create-tree-response.json'248 );249 const getCommitResponse = {250 headers: {},251 status: 200,252 url: 'http://fake-url.com',253 data: commitResponseData,254 } as unknown as GetCommitResponse;255 const createTreeResponse = {256 headers: {},257 status: 201,258 url: 'http://fake-url.com',259 data: createTreeResponseData,260 } as unknown as CreateTreeResponse;261 const createCommitResponseData = await import(262 './fixtures/create-commit-response.json'263 );264 const createCommitResponse = {265 headers: {},266 status: 201,267 url: 'http://fake-url.com',268 data: createCommitResponseData,269 } as unknown as CreateCommitResponse;270 afterEach(() => {271 sandbox.restore();272 });273 it('When everything works it calls functions with correct parameter values', async () => {274 // setup275 const stubGetCommit = sandbox276 .stub(octokit.git, 'getCommit')277 .resolves(getCommitResponse);278 const stubCreateTree = sandbox279 .stub(octokit.git, 'createTree')280 .resolves(createTreeResponse);281 const stubCreateCommit = sandbox282 .stub(octokit.git, 'createCommit')283 .resolves(createCommitResponse);284 const stubUpdateRef = sandbox.stub(octokit.git, 'updateRef');285 // tests286 await handler.commitAndPush(287 octokit,288 oldHeadSha,289 changes,290 {branch: branchName, ...origin},291 message,292 true293 );294 sandbox.assert.calledOnceWithExactly(stubGetCommit, {295 owner: origin.owner,296 repo: origin.repo,297 commit_sha: oldHeadSha,298 });299 sandbox.assert.calledWithExactly(stubCreateTree, {300 owner: origin.owner,301 repo: origin.repo,302 tree: [],303 base_tree: getCommitResponse.data.tree.sha,304 });305 sandbox.assert.calledOnceWithExactly(stubCreateCommit, {306 owner: origin.owner,307 repo: origin.repo,308 message,309 tree: createTreeResponse.data.sha,310 parents: [oldHeadSha],311 });312 sandbox.assert.calledOnceWithExactly(stubUpdateRef, {313 owner: origin.owner,314 repo: origin.repo,315 sha: createCommitResponse.data.sha,316 ref: 'heads/test-branch-name',317 force: true,318 });319 });320 it('Forwards GitHub error if getCommit fails', async () => {321 const error = new Error('Error committing');322 sandbox.stub(octokit.git, 'getCommit').rejects(error);323 await assert.rejects(handler.createTree(octokit, origin, '', []), error);324 });325 it('Forwards GitHub error if createTree fails', async () => {326 // setup327 const error = new Error('Error committing');328 sandbox.stub(octokit.git, 'getCommit').resolves(getCommitResponse);329 sandbox.stub(octokit.git, 'createTree').rejects(error);330 // tests331 await assert.rejects(handler.createTree(octokit, origin, '', []), error);332 });...
github.ts
Source:github.ts
...29 ref: this.options.ref,30 })31 const headCommitSha = refResponse.data.object.sha32 // Grab the commit that HEAD points to33 const headCommit = await this.octokit.git.getCommit({34 owner: this.options.owner,35 repo: this.options.repo,36 commit_sha: headCommitSha,37 })38 const headCommitTreeSha = headCommit.data.tree.sha39 // Create blob40 const blob = await this.octokit.git.createBlob({41 owner: this.options.owner,42 repo: this.options.repo,43 content,44 encoding: 'utf-8',45 })46 const blobSha = blob.data.sha47 // Create tree48 const tree = await this.octokit.git.createTree({49 owner: this.options.owner,50 repo: this.options.repo,51 base_tree: headCommitTreeSha,52 tree: [53 {54 path,55 mode: '100644',56 type: 'blob',57 sha: blobSha,58 },59 ],60 })61 const newTreeSha = tree.data.sha62 // Create commit63 const newCommit = await this.octokit.git.createCommit({64 owner: this.options.owner,65 repo: this.options.repo,66 message: commitMessage,67 tree: newTreeSha,68 parents: [69 headCommitSha,70 ],71 })72 const newCommitSha = newCommit.data.sha73 // Update a reference74 const newHeadRef = await this.octokit.git.updateRef({75 owner: this.options.owner,76 repo: this.options.repo,77 ref: this.options.ref,78 sha: newCommitSha,79 })80 return true81 // // const commit = await octokit.git.getCommit({82 // // owner,83 // // repo,84 // // // commit_sha85 // // })86 // // .then(({ data }) => {87 // // // handle data88 // // })89 // // const {90 // // query: { pid }91 // // } = req;92 // // const pid = 193 // res.json({94 // // refResponse,95 // // headCommit,96 // newHeadRef,97 // })98 // };99 }100 public async exec<T>(fn: (octokit: Octokit) => Promise<T>): Promise<T> {101 return fn(this.octokit)102 }103 public async getFileContent(path: string): Promise<string> {104 const content = await this.octokit.repos.getContents({105 owner: this.options.owner,106 repo: this.options.repo,107 path,108 })109 const buffer = Buffer.from(content.data.content, 'base64')110 return buffer.toString('utf-8')111 }112 public async getFileBlob(path: string): Promise<string> {113 const refResponse = await this.octokit.git.getRef({114 owner: this.options.owner,115 repo: this.options.repo,116 ref: this.options.ref,117 })118 const headCommitSha = refResponse.data.object.sha119 const headCommit = await this.octokit.git.getCommit({120 owner: this.options.owner,121 repo: this.options.repo,122 commit_sha: headCommitSha,123 })124 const treeSha = headCommit.data.tree.sha125 const tree = await this.octokit.git.getTree({126 owner: this.options.owner,127 repo: this.options.repo,128 tree_sha: treeSha,129 })130 const file = tree.data.tree.find(f => f.path === path)131 if (!file) {132 return null133 }...
index.js
Source:index.js
2const validateMessage = require('./lib/validate-message.js');3async function main() {4 const octokit = createOctokit();5 const [ owner, repo ] = process.env.GITHUB_REPOSITORY.split('/');6 const commit = await octokit.git.getCommit({ owner, repo, commit_sha: process.env.GITHUB_SHA });7 try {8 await validateMessage(commit.data.message);9 console.log('\n\nThis commit looks beautiful\n\n');10 process.exit(0);11 } catch (err) {12 console.log(`\n\n${err.message}\n\n`);13 process.exit(1);14 }15}...
Using AI Code Generation
1const { Octokit } = require("@octokit/rest");2const { createTokenAuth } = require("@octokit/auth-token");3const octokit = new Octokit({4});5 .getCommit({6 })7 .then((result) => console.log(result));8const { Octokit } = require("@octokit/rest");9const { createTokenAuth } = require("@octokit/auth-token");10const octokit = new Octokit({11});12async function getCommit() {13 const result = await octokit.git.getCommit({14 });15 console.log(result);16}17getCommit();18const { Octokit } = require("@octokit/rest");19const { createTokenAuth } = require("@octokit/auth-token");20const octokit = new Octokit({21});22async function getCommit() {23 try {24 const result = await octokit.git.getCommit({25 });26 console.log(result);27 } catch (error) {28 console.log(error);29 }30}31getCommit();
Using AI Code Generation
1const { Octokit } = require("@octokit/rest");2const octokit = new Octokit({3});4 .getCommit({5 })6 .then((response) => {7 console.log(response);8 });9const { Octokit } = require("@octokit/rest");10const octokit = new Octokit({11});12 .getCommit({13 })14 .then((response) => {15 console.log(response);16 });17const { Octokit } = require("@octokit/rest");18const octokit = new Octokit({19});20 .getCommit({21 })22 .then((response) => {23 console.log(response);24 });25const { Octokit } = require("@octokit/rest");26const octokit = new Octokit({27});28 .getCommit({
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!