Best JavaScript code snippet using best
git-app.ts
Source:git-app.ts
...82 auth: `Bearer ${token}`83 });84 return github;85 }86 async authenticateAsInstallation(installationId?: number, gitOpts = this.gitOpts) {87 if (!installationId) {88 throw new Error ('installationId is required to authenticate as user');89 }90 const token = await this.createInstallationToken(installationId, gitOpts);91 const github = new Octokit({92 ...gitOpts,93 auth: `token ${token}`94 });95 return github;96 }97 async createInstallationToken(installation_id: number, gitOpts = this.gitOpts) {98 if (!installation_id) {99 throw new Error ('installation_id is required to authenticate as user');100 }101 const github = await this.authenticateAsApplication(gitOpts);102 const response = await github.apps.createInstallationToken({103 installation_id,104 });105 106 return response.data.token;107 }108 async authenticateAsAppAndInstallation(git: { repo: string, owner: string }, gitOpts = this.gitOpts) {109 const gitAppAuth = await this.authenticateAsApplication();110 111 const repoInstallation = await gitAppAuth.apps.getRepoInstallation(git);112 const installationId = repoInstallation.data.id;113 114 return this.authenticateAsInstallation(installationId);115 }116}117export default function GithubApplicationFactory(118 { applicationId , certificate, userToken }: Partial<GithubFactoryConfig> = { applicationId: GITHUB_APP_ID, certificate: GITHUB_APP_CERTIFICATE, userToken: GITHUB_USER_TOKEN },119 githubClientOptions: Octokit.Options = {},120) {121 const { baseUrl } = githubClientOptions;122 if (baseUrl) {123 const agent = new https.Agent({ rejectUnauthorized: false });124 githubClientOptions = { agent, baseUrl };125 }126 return new GithubFactory({ applicationId, certificate, userToken }, githubClientOptions);...
github-app.js
Source:github-app.js
...41 async authenticateAsApp(){42 const octokit = new Octokit({auth: generateJwt(this.id, this.cert)})43 return octokit44 }45 async authenticateAsInstallation(installation_id){46 const octokit = await this.authenticateAsApp()47 const response = await octokit.apps.createInstallationAccessToken({installation_id})48 return new Octokit({auth: response.data.token}) 49 }50 /**51 * Get all repositories the installation has access to.52 * 53 * This method is augumented by {@link module:docloop#cache}(2000). Return values will be cached for 2 seconds, to prevent huge numbers of API calls.54 * 55 * @param {String} installation_id GithubApp installation id56 * @return {Object[]} For each repository a subset of the data provided by github.57 */58 async getRepositories(installation_id){59 const octokit = await this.authenticateAsInstallation(installation_id)60 var response = await octokit.apps.listReposAccessibleToInstallation({per_page: 100}),61 repos = response.data.repositories || []62 //TODO: HANDLE MORE THAN 100 PAGES63 return repos.map( repository => ({64 name: repository.name,65 full_name: repository.full_name,66 owner: repository.owner,67 installation_id: installation_id,68 html_url: repository.html_url69 }))70 }71 /**72 * Create or Update an Issue. If issue.number is provided, update the corresponding issue, otherwise create a new one .73 * 74 * @param {Identifier} target_identifier Identifier pointing at a github repository75 * @param {Issue} issue 76 * @return {String} The github issue number77 */78 async createOrUpdateIssue(target_identifier, issue){79 console.log('creating/upadating issue', issue.title, Date.now())80 const octokit = await this.authenticateAsInstallation(target_identifier.installation_id)81 var params = { 82 owner: target_identifier.owner,83 repo: target_identifier.repo,84 number: issue.number,85 title: issue.title,86 body: issue.body,87 labels: issue.labels88 },89 result = issue.number 90 ? await octokit.issues.update( params ) 91 : await octokit.issues.create( params ) 92 console.log('done', issue.title)93 return result.data.number94 }95 /**96 * Create or update an Issue. If comment.id is provided, update the corresponding comment, otherwise create a new one.97 * 98 * @param {Identifier} target_identifier Identifier pointing at a github repository99 * @param {Comment} comment 100 * @return {String} The github comment number101 */102 async createOrUpdateComment(target_identifier, comment){103 console.log('creating/updating comment', Date.now())104 const octokit = await this.authenticateAsInstallation(target_identifier.installation_id)105 var params = {106 owner: target_identifier.owner,107 repo: target_identifier.repo,108 number: comment.number,109 body: comment.body,110 id: comment.id111 },112 result = comment.id 113 ? await octokit.issues.updateComment( params )114 : await octokit.issues.createComment( params )115 116 return result.data.id //todo? 117 }118}...
Using AI Code Generation
1var BestBuy = require('bestbuy');2var bb = new BestBuy('your-api-key-here');3bb.authenticateAsInstallation(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var BestBuy = require('bestbuy');11var bb = new BestBuy('your-api-key-here');12bb.authenticateAsInstallation(function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var BestBuy = require('bestbuy');20var bb = new BestBuy('your-api-key-here');21bb.authenticateAsInstallation(function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var BestBuy = require('bestbuy');29var bb = new BestBuy('your-api-key-here');30bb.authenticateAsInstallation(function(err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var BestBuy = require('bestbuy');38var bb = new BestBuy('your-api-key-here');39bb.authenticateAsInstallation(function(err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});
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!!