How to use octokit.repos.createOrUpdateFileContents method in qawolf

Best JavaScript code snippet using qawolf

index.js

Source:index.js Github

copy

Full Screen

...40 // template files needed for Docsify41 if (!docsFolder.data.some((dir) => dir.path === "docs")) {42 console.log("docs folder does not exist, setting up initial templates");43 console.log("writing nojekyll file");44 const jekyllRes = await octokit.repos.createOrUpdateFileContents({45 owner: ctx.repo.owner,46 repo: ctx.repo.repo,47 path: "docs/.nojekyll",48 message: "initial template setup",49 content: Buffer.from(fileContentsToWrite["nojekyll"]).toString(50 "base64"51 ),52 branch: ctx.ref,53 });54 console.log("writing glossary file");55 const glossaryRes = await octokit.repos.createOrUpdateFileContents({56 owner: ctx.repo.owner,57 repo: ctx.repo.repo,58 path: "docs/_glossary.md",59 message: "initial template setup",60 content: Buffer.from(fileContentsToWrite["_glossarymd"]).toString(61 "base64"62 ),63 branch: ctx.ref,64 });65 console.log("writing readme file");66 const readmeRes = await octokit.repos.createOrUpdateFileContents({67 owner: ctx.repo.owner,68 repo: ctx.repo.repo,69 path: "docs/README.md",70 message: "initial template setup",71 content: Buffer.from(fileContentsToWrite["readmemd"]).toString(72 "base64"73 ),74 branch: ctx.ref,75 });76 console.log("writing index file");77 const indexRes = await octokit.repos.createOrUpdateFileContents({78 owner: ctx.repo.owner,79 repo: ctx.repo.repo,80 path: "docs/index.html",81 message: "initial template setup",82 content: Buffer.from(fileContentsToWrite["indexhtml"]).toString(83 "base64"84 ),85 branch: ctx.ref,86 });87 console.log("writing css file");88 const cssRes = await octokit.repos.createOrUpdateFileContents({89 owner: ctx.repo.owner,90 repo: ctx.repo.repo,91 path: "docs/styles.css",92 message: "initial template setup",93 content: Buffer.from(fileContentsToWrite["stylescss"]).toString(94 "base64"95 ),96 branch: ctx.ref,97 });98 } else {99 console.log("docs folder does exist, skipping initial template setup");100 // TODO101 // Verify the template version number102 // if it is different from master copy over new template files103 // can probably be done with OR statement in top level condition check104 // data.content is encoded content of file105 // pass to parser to get version out and then compare106 }107 // Always recreate the sidebar, this will allow easy updates when objectives108 // Are added to thr course.yml109 // Read docs folder to see if sidebar exists110 const docsContent = await octokit.repos.getContent({111 owner: ctx.repo.owner,112 repo: ctx.repo.repo,113 ref: ctx.ref,114 path: "docs",115 });116 // if sidebar, then read it for the sha117 if (docsContent.data.some((file) => file.name === "_sidebar.md")) {118 console.log("Getting the sidebar");119 const sidebar = await octokit.repos.getContent({120 owner: ctx.repo.owner,121 repo: ctx.repo.repo,122 ref: ctx.ref,123 path: "docs/_sidebar.md",124 });125 console.log("updating existing sidebar file");126 const sidebarRes = await octokit.repos.createOrUpdateFileContents({127 owner: ctx.repo.owner,128 repo: ctx.repo.repo,129 path: "docs/_sidebar.md",130 message: "initial template setup",131 content: Buffer.from(fileContentsToWrite["_sidebarmd"]).toString(132 "base64"133 ),134 branch: ctx.ref,135 sha: sidebar.data.sha,136 });137 } else {138 // if not sidebar then just create a new one with no sha139 console.log("writing a new sidebar file");140 const sidebarRes = await octokit.repos.createOrUpdateFileContents({141 owner: ctx.repo.owner,142 repo: ctx.repo.repo,143 path: "docs/_sidebar.md",144 message: "initial template setup",145 content: Buffer.from(fileContentsToWrite["_sidebarmd"]).toString(146 "base64"147 ),148 branch: ctx.ref,149 });150 }151 // For each objective we need to see if it already exists in the repo to152 // Prevent overwriting a lesson plan with the template153 console.log("Creating files to serve");154 for (let i = 0; i < pageTitles.length; i++) {155 // Check to see if a lesson plan with the current name already exists in the docs folder156 // If it does not exist, then create one with the template on the current branch157 const filenameSlug = slugify(pageTitles[i]);158 if (159 !docsContent.data.some(160 (lessonPlan) => lessonPlan.name === `${filenameSlug}.md`161 )162 ) {163 console.log("trying to write " + filenameSlug + ".md to docs folder");164 const res = await octokit.repos.createOrUpdateFileContents({165 owner: ctx.repo.owner,166 repo: ctx.repo.repo,167 path: `docs/${filenameSlug}.md`,168 message: "initial template setup",169 content: Buffer.from(170 fileContentsToWrite["template-documentmd"]171 ).toString("base64"),172 branch: ctx.ref,173 });174 } else {175 console.log(176 `${filenameSlug}.md already exists, skipping to next objective`177 );178 // If it does exist then continue through the remaining files...

Full Screen

Full Screen

commitApiDoc.test.js

Source:commitApiDoc.test.js Github

copy

Full Screen

1const commitApiDoc = require('../commitApiDoc');2const octokit = {3 repos: {4 getContent: jest.fn(),5 createOrUpdateFileContents: jest.fn(),6 }7};8const run = () => {9 return commitApiDoc({10 octokit,11 owner: 'my-org',12 repo: 'my-repo',13 ref: 'my-branch',14 file: {15 name: 'project1_hello.html',16 content: 'IyBHcm91cCBIZWxsbyBTZXJ2aWNlCgojIyBHRVQgL2hlbGxvCisgUmVzcG9uc2UgMjAwICh0ZXh0L3BsYWluKQoKICAgICAgICBIZWxsbyEK',17 }18 });19};20describe('commitApiDoc', () => {21 afterEach(() => {22 jest.clearAllMocks();23 });24 it('when file do not exists in repository its should be created', async () => {25 octokit.repos.getContent26 .mockImplementation(() => Promise.reject(Error('Not Found')));27 octokit.repos.createOrUpdateFileContents28 .mockResolvedValue({29 data: {30 content: {31 name: 'project1_hello.html',32 path: 'project1_hello.html',33 sha: 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'34 }35 }36 });37 await run();38 expect(octokit.repos.getContent).toHaveBeenCalledWith({39 owner: 'my-org',40 repo: 'my-repo',41 ref: 'my-branch',42 path: 'project1_hello.html',43 });44 expect(octokit.repos.createOrUpdateFileContents).toHaveBeenCalledWith({45 owner: 'my-org',46 repo: 'my-repo',47 path: 'project1_hello.html',48 message: 'Commiting file project1_hello.html',49 content: 'IyBHcm91cCBIZWxsbyBTZXJ2aWNlCgojIyBHRVQgL2hlbGxvCisgUmVzcG9uc2UgMjAwICh0ZXh0L3BsYWluKQoKICAgICAgICBIZWxsbyEK',50 branch: 'my-branch',51 });52 });53 it('when file exists in repository the file should be updated', async () => {54 octokit.repos.getContent55 .mockResolvedValue({56 data: {57 name: 'project1_hello.html',58 path: 'project1_hello.html',59 sha: '3d21ec53a331a6f037a91c368710b99387d012c1',60 }61 });62 octokit.repos.createOrUpdateFileContents63 .mockResolvedValue({64 data: {65 content: {66 name: 'project1_hello.html',67 path: 'project1_hello.html',68 sha: 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'69 }70 }71 });72 await run();73 expect(octokit.repos.getContent).toHaveBeenCalledWith({74 owner: 'my-org',75 repo: 'my-repo',76 ref: 'my-branch',77 path: 'project1_hello.html',78 });79 expect(octokit.repos.createOrUpdateFileContents).toHaveBeenCalledWith({80 owner: 'my-org',81 repo: 'my-repo',82 path: 'project1_hello.html',83 message: 'Commiting file project1_hello.html',84 content: 'IyBHcm91cCBIZWxsbyBTZXJ2aWNlCgojIyBHRVQgL2hlbGxvCisgUmVzcG9uc2UgMjAwICh0ZXh0L3BsYWluKQoKICAgICAgICBIZWxsbyEK',85 sha: '3d21ec53a331a6f037a91c368710b99387d012c1',86 branch: 'my-branch',87 });88 });...

Full Screen

Full Screen

example.js

Source:example.js Github

copy

Full Screen

...16 repo: "blahblah",17 path: filePath,18}).then((olddata) => {19 console.log(olddata);20 octokit.repos.createOrUpdateFileContents({21 owner: 'chienwen',22 repo: 'blahblah',23 path: filePath,24 message: 'updating ' + (new Date).getTime(),25 content: base64.encode(content),26 sha: olddata.data.sha27 }).then((data) => {28 console.log(data);29 }).catch((err) => {30 console.log(err)31 });32}).catch((err) => {33 console.log(err);34 if (err.status === 404) {35 octokit.repos.createOrUpdateFileContents({36 owner: 'chienwen',37 repo: 'blahblah',38 path: filePath,39 message: 'creating ' + (new Date).getTime(),40 content: base64.encode(content),41 }).then((data) => {42 console.log(data);43 console.log('created', data.data.content.sha);44 testsha = data.data.content.sha;45 /*46 octokit.repos.createOrUpdateFileContents({47 owner: 'chienwen',48 repo: 'blahblah',49 path: filePath,50 message: 'updating ' + (new Date).getTime(),51 content: base64.encode('bingo'),52 sha: testsha53 }).then((data) => {54 console.log(data);55 }).catch((err) => {56 console.log(err)57 });58 */59 }).catch((err) => {60 console.log(err)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Octokit } = require("@octokit/rest");2const { createTokenAuth } = require("@octokit/auth-token");3const octokit = new Octokit({4});5const createFile = async () => {6 try {7 const res = await octokit.repos.createOrUpdateFileContents({8 });9 console.log(res);10 } catch (error) {11 console.log(error);12 }13};14createFile();

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run qawolf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful