How to use appOctokit method in argos

Best JavaScript code snippet using argos

routes.js

Source:routes.js Github

copy

Full Screen

1const express = require('express');2const axios = require('axios');3const fs = require('fs');4const { Octokit } = require('@octokit/core');5const { createAppAuth, createOAuthUserAuth } = require('@octokit/auth-app');6require('dotenv').config();7const privateKey = fs.readFileSync('./.data/private.pem', { encoding: 'utf8' });8const router = express.Router();9const api = axios.create({10 baseURL: 'https://api.github.com',11});12router.get('/', function (req, res) {13 res.send('Welcome to the Webhooks API');14});15router.post('/github-webhook', async function (req, res) {16 const appOctokit = new Octokit({17 authStrategy: createAppAuth,18 auth: {19 appId: process.env.GITHUB_APP,20 privateKey: privateKey,21 clientId: process.env.GITHUB_CLIENT,22 clientSecret: process.env.GITHUB_SECRET,23 installationId: process.env.GITHUB_INSTALLATION,24 },25 });26 const payload = req.body;27 if (28 payload.action === 'opened' &&29 payload.issue?.title.includes('[element]') &&30 !Object.keys(payload).includes('pull_request')31 ) {32 try {33 await appOctokit.request(34 `PATCH /repos/apptension/openwind/issues/${payload.issue.number}`,35 { labels: ['element', 'todo'] }36 );37 } catch (e) {38 res.status(500);39 }40 }41 if (42 payload.action === 'created' &&43 payload.comment.body.includes('in progress') &&44 !Object.keys(payload).includes('pull_request')45 ) {46 try {47 await appOctokit.request(48 `PATCH /repos/apptension/openwind/issues/${payload.issue.number}`,49 {50 labels: ['element', 'in progress'],51 assignees: [...payload.issue.assignees, payload.sender.login],52 }53 );54 } catch (e) {55 res.status(500);56 }57 }58 console.log(payload);59 if (60 (payload.action === 'created' || payload.action === 'submitted') &&61 Object.keys(payload.issue).includes('pull_request')62 ) {63 if (payload.comment.body.toLowerCase().includes('resolves')) {64 const issueId = payload.comment.body65 .match(/#\d+/)[0]66 .replace(/^\D+/g, '');67 try {68 console.log('INSIDE');69 await appOctokit.request(70 `PATCH /repos/apptension/openwind/issues/${issueId}`,71 {72 labels: ['element', 'review'],73 }74 );75 } catch (e) {76 res.status(500);77 }78 }79 if (payload.comment.body.toLowerCase().includes('approved')) {80 const issueId = payload.comment.body81 .match(/#\d+/)[0]82 .replace(/^\D+/g, '');83 try {84 await appOctokit.request(85 `PATCH /repos/apptension/openwind/issues/${issueId}`,86 {87 labels: ['element', 'done'],88 }89 );90 } catch (e) {91 res.status(500);92 }93 }94 }95 if (96 payload.action === 'opened' &&97 Object.keys(payload).includes('pull_request')98 ) {99 if (payload.pull_request.body.toLowerCase().includes('resolves')) {100 const issueId = payload.pull_request.body101 .match(/#\d+/)[0]102 .replace(/^\D+/g, '');103 try {104 console.log('INSIDE');105 await appOctokit.request(106 `PATCH /repos/apptension/openwind/issues/${issueId}`,107 {108 labels: ['element', 'review'],109 }110 );111 } catch (e) {112 res.status(500);113 }114 }115 }116 res.status(201).send({117 message: 'Webhook Event successfully logged',118 });119});...

Full Screen

Full Screen

main.ts

Source:main.ts Github

copy

Full Screen

1import {Octokit} from '@octokit/rest';2import * as core from '@actions/core';3import {createAppAuth} from '@octokit/auth-app';4async function getAuthenticatedApp(5 githubAppId: string,6 pemContent: string7): Promise<Octokit> {8 // Create octokit app with basic app id authentication9 const appOctokit = new Octokit({10 authStrategy: createAppAuth,11 auth: {12 appId: githubAppId,13 privateKey: pemContent,14 },15 baseUrl: process.env.GITHUB_API_URL || 'https://api.github.com',16 });17 return appOctokit;18}19async function getJWT(appOctokit: Octokit): Promise<void> {20 // Get Github App JWT using the appOctokit object21 try {22 const appAuthentication: any = await appOctokit.auth({type: 'app'});23 core.setSecret(appAuthentication.token);24 core.setOutput('jwt_token', appAuthentication.token);25 } catch (error: any) {26 const errormessage =27 'Not able to retrieve a JWT: ' + new Error(error).message;28 core.setFailed(errormessage);29 throw new Error(errormessage);30 }31}32async function findProperInstallationId(33 appOctokit: Octokit,34 installationId: string35): Promise<string> {36 // Either confirm if given installation id is valid or find the first occurrence in the installation list37 let installation;38 const installations = await appOctokit.apps.listInstallations();39 if (installationId) {40 installation = installations?.data.find(41 (item: any) => item.id === Number(installationId)42 );43 } else {44 installation = installations?.data[0];45 }46 const resp = installation ? installation.id.toString() : '';47 return Promise.resolve(resp);48}49async function getInstallationAccessToken(50 appOctokit: Octokit,51 installationId: string52): Promise<void> {53 // Get Installation Access-Token54 try {55 const resp: any = await appOctokit.auth({56 type: 'installation',57 installationId,58 });59 core.setSecret(resp.token);60 core.setOutput('installation_access_token', resp.token);61 } catch (error: any) {62 const errormessage =63 'Not able to retrieve the installation access token: ' +64 new Error(error).message;65 core.setFailed(errormessage);66 throw new Error(errormessage);67 }68}69async function run(70 encoded_pem: string,71 appId: string,72 installationId: string73): Promise<void> {74 const decodedPem = Buffer.from(encoded_pem, 'base64').toString('binary');75 const appOctokit = await getAuthenticatedApp(appId, decodedPem);76 await getJWT(appOctokit);77 const verifiedInstallationId = await findProperInstallationId(78 appOctokit,79 installationId80 );81 if (verifiedInstallationId) {82 await getInstallationAccessToken(appOctokit, verifiedInstallationId);83 } else {84 console.log('Not able to find a valid installation id');85 }86}87// Collecting inputs88const appId: string = core.getInput('app_id');89const encodedPemFile: string = core.getInput('base64_pem_key');90const installationId: string = core.getInput('installation_id');...

Full Screen

Full Screen

checks.js

Source:checks.js Github

copy

Full Screen

1import { Octokit } from "@octokit/rest"2import { createAppAuth } from "@octokit/auth-app"3const OWNER = process.env['owner']4const REPO = process.env['repo']5const INSTALLATION_ID = 1006const PULL_NUMBER = 17const APP_ID = process.env['app_id']8const appOctokit = new Octokit({9 authStrategy: createAppAuth,10 auth: {11 appId: APP_ID,12 privateKey: process.env["client_secret"],13 // optional: this will make appOctokit authenticate as app (JWT)14 // or installation (access token), depending on the request URL15 installationId: INSTALLATION_ID,16 },17});18// const { data } = await appOctokit.request("/app");19const { token } = await appOctokit.auth({20 type: "installation",21 // defaults to `options.auth.installationId` set in the constructor22 installationId: INSTALLATION_ID,23})24// const { data: pullRequest } = await octokit.rest.pulls.get({25// owner: OWNER,26// repo: REPO,27// pull_number: 1,28// });29const now = new Date()30await appOctokit.request(`POST /repos/${OWNER}/${REPO}/check-runs`, {31 owner: OWNER,32 repo: REPO,33 name: "test",34 head_sha: '7e6396ad182aa25cdf982aa73187e4bead5e15b2',35 status: 'in_progress', //completed,in_progress36 external_id: '42',37 started_at: now.getTime(),38 output: {39 title: 'Testing Simply report',40 summary: 'just kidding',41 text: 'hey'42 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { appOctokit } = require("argos-ci");2const { createAppAuth } = require("@octokit/auth-app");3const auth = createAppAuth({4});5const octokit = appOctokit(auth);6 .list({7 })8 .then(({ data }) => {9 console.log(data);10 });11const { appOctokit } = require("argos-ci");12const { createAppAuth } = require("@octokit/auth-app");13const auth = createAppAuth({14});15const octokit = appOctokit(auth);16 .listForOrg({17 })18 .then(({ data }) => {19 console.log(data);20 });21const { appOctokit } = require("argos-ci");22const { createAppAuth } = require("@octokit/auth-app");23const auth = createAppAuth({24});25const octokit = appOctokit(auth);26octokit.graphql(27 query($owner: String!, $name: String!) {28 repository(owner: $owner, name: $name) {29 owner {30 }31 }32 }

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = function (options) {2 options = seneca.util.deepextend({3 }, options)4 seneca.add({role: plugin, cmd: 'test'}, test)5 seneca.add({role: plugin, cmd: 'test2'}, test2)6 function test (args, done) {7 seneca.act({role: 'appOctokit', cmd: 'appOctokit'}, (err, octokit) => {8 if (err) {9 return done(err)10 }11 octokit.repos.listForOrg({12 }).then((result) => {13 done(null, result)14 }).catch((err) => {15 done(err)16 })17 })18 }19 function test2 (args, done) {20 seneca.act({role: 'appOctokit', cmd: 'appOctokit'}, (err, octokit) => {21 if (err) {22 return done(err)23 }24 octokit.repos.listForOrg({25 }).then((result) => {26 done(null, result)27 }).catch((err) => {28 done(err)29 })30 })31 }32 return {33 }34}35module.exports = function (options) {36 options = seneca.util.deepextend({37 }, options)38 seneca.add({role: plugin, cmd: 'test'}, test)39 seneca.add({role: plugin, cmd: 'test2'}, test2)40 function test (args, done) {41 seneca.act({role: 'appOctokit', cmd: 'appOctokit'}, (err, octokit) => {42 if (err) {43 return done(err)44 }45 octokit.repos.listForOrg({46 }).then((result) => {47 done(null, result)48 }).catch((err) => {49 done(err)50 })51 })52 }53 function test2 (args, done) {54 seneca.act({role: 'app

Full Screen

Using AI Code Generation

copy

Full Screen

1const { appOctokit } = require("argos-ci");2const { github } = require("argos-ci");3const { getCommit } = require("argos-ci");4const { getCommitFromRef } = require("argos-ci");5const { getCommitFromSha } = require("argos-ci");6const { getCommitFromTag } = require("argos-ci");7const { getCommitFromPullRequest } = require("argos-ci");8const { getCommitFromBranch } = require("argos-ci");9const { getCommitFromDefaultBranch } = require("argos-ci");10const { getCommitFromHeadBranch } = require("argos-ci");11const { getCommitFromBaseBranch } = require("argos-ci");12const { getCommitFromPullRequestHeadBranch } = require("argos-ci");13const { getCommitFromPullRequestBaseBranch } = require("argos-ci");14const { getCommitFromPullRequestHeadSha } = require("argos-ci");15const { getCommitFromPullRequestBaseSha } = require("argos-ci");16const { getCommitFromPullRequestHeadTag } = require("argos-ci");17const { getCommitFromPullRequestBaseTag } = require("argos-ci");

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosy = require('argosy')2var octokit = require('argosy-github-octokit')3var pattern = require('argosy-pattern')4var service = argosy()5service.use(octokit())6service.act(pattern({7 appOctokit: {8 params: {9 }10 }11}), function (err, result) {12 if (err) {13 console.error(err)14 }15 console.log(result)16})17### argosy-github-octokit(opts)

Full Screen

Using AI Code Generation

copy

Full Screen

1const argosy = require('argosy')2const github = argosy({3 octokit: require('@octokit/rest')()4})5github.appOctokit.authenticate({6})7github.appOctokit.apps.createInstallationToken({8}).then(response => {9 const octokit = github.appOctokit(response.data.token)10 octokit.issues.create({11 })12})

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 argos 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