Best JavaScript code snippet using argos
github.service.ts
Source:github.service.ts
...43 }44 async getGitRemoteOrganization(45 installationId: string46 ): Promise<RemoteGitOrganization> {47 const octokit = await this.getInstallationOctokit(installationId);48 const gitRemoteOrganization = await octokit.rest.apps.getInstallation({49 // eslint-disable-next-line @typescript-eslint/naming-convention50 installation_id: GithubService.convertToNumber(installationId)51 });52 const { data: gitRemoteOrgs } = gitRemoteOrganization;53 return {54 name: gitRemoteOrgs.account.login,55 type: EnumGitOrganizationType[gitRemoteOrganization.data.account.type]56 };57 }58 async deleteGitOrganization(installationId: string): Promise<boolean> {59 const octokit = await this.getInstallationOctokit(installationId);60 const deleteInstallationRes = await octokit.rest.apps.deleteInstallation({61 // eslint-disable-next-line @typescript-eslint/naming-convention62 installation_id: GithubService.convertToNumber(installationId)63 });64 if (deleteInstallationRes.status != 204) {65 throw new AmplicationError('delete installationId {} failed');66 }67 return true;68 }69 async getGitInstallationUrl(workspaceId: string): Promise<string> {70 return this.gitInstallationUrl.replace('{state}', workspaceId);71 }72 private static async isRepoExistWithOctokit(73 octokit: Octokit,74 name: string75 ): Promise<boolean> {76 const repos = await GithubService.getOrganizationReposWithOctokit(octokit);77 return repos.map(repo => repo.name).includes(name);78 }79 async isRepoExist(installationId: string, name: string): Promise<boolean> {80 const octokit = await this.getInstallationOctokit(installationId);81 return await GithubService.isRepoExistWithOctokit(octokit, name);82 }83 async createUserRepository(84 installationId: string,85 owner: string,86 name: string87 ): Promise<RemoteGitRepository> {88 throw new AmplicationError(UNSUPPORTED_GIT_ORGANIZATION_TYPE);89 }90 async createOrganizationRepository(91 installationId: string,92 owner: string,93 name: string94 ): Promise<RemoteGitRepository> {95 const octokit = await this.getInstallationOctokit(installationId);96 const exists: boolean = await GithubService.isRepoExistWithOctokit(97 octokit,98 name99 );100 if (exists) {101 throw new AmplicationError(REPO_NAME_TAKEN_ERROR_MESSAGE);102 }103 const { data: repo } = await octokit.rest.repos.createInOrg({104 name: name,105 org: owner,106 // eslint-disable-next-line @typescript-eslint/naming-convention107 auto_init: true108 });109 return {110 name: repo.name,111 url: repo.html_url,112 private: repo.private,113 fullName: repo.full_name,114 admin: repo.permissions.admin115 };116 }117 private static async getOrganizationReposWithOctokit(118 octokit: Octokit119 ): Promise<RemoteGitRepository[]> {120 const results = await octokit.request('GET /installation/repositories');121 return results.data.repositories.map(repo => ({122 name: repo.name,123 url: repo.html_url,124 private: repo.private,125 fullName: repo.full_name,126 admin: repo.permissions.admin127 }));128 }129 async getOrganizationRepos(130 installationId: string131 ): Promise<RemoteGitRepository[]> {132 const octokit = await this.getInstallationOctokit(installationId);133 return await GithubService.getOrganizationReposWithOctokit(octokit);134 }135 private async getInstallationOctokit(136 installationId: string137 ): Promise<Octokit> {138 const installationIdNumber = GithubService.convertToNumber(installationId);139 return await this.app.getInstallationOctokit(installationIdNumber);140 }141 /**142 * Gets a file from GitHub - Currently only returns the content of a single file and only if it is base64 encoded . Otherwise, returns null143 * @param userName144 * @param repoName145 * @param path146 * @param baseBranchName147 * @param installationId148 */149 async getFile(150 userName: string,151 repoName: string,152 path: string,153 baseBranchName: string,154 installationId: string155 ): Promise<GithubFile> {156 const octokit = await this.getInstallationOctokit(installationId);157 const content = await octokit.rest.repos.getContent({158 owner: userName,159 repo: repoName,160 path,161 ref: baseBranchName ? baseBranchName : undefined162 });163 if (!Array.isArray(content)) {164 const item = content.data as DirectoryItem;165 if (item.type === GITHUB_FILE_TYPE) {166 // Convert base64 results to UTF-8 string167 const buff = Buffer.from(item.content, 'base64');168 const file: GithubFile = {169 content: buff.toString('utf-8'),170 htmlUrl: item.html_url,...
github.ts
Source:github.ts
...3import { PullRequest } from '@octokit/webhooks-types'4import { channelNameFromPull, pathToAppUrl } from './util'5const GITHUB_COMMENT_MARKER = 'live-github-managed-comment'6export const addOrUpdateManagedComment = async (githubApp: GithubApp, pull: PullRequest): Promise<void> => {7 const octokit = await githubApp.getInstallationOctokit(parseInt(process.env.GITHUB_INSTALLATION_ID!))8 const channelName = channelNameFromPull(pull)9 const openSlackUrl = pathToAppUrl(`/app/openSlackChannel/v1/${pull.base.repo.name}/${pull.number}`)10 const existingComments = await getPullComments(githubApp, pull)11 const existingManagedComment = existingComments.find(comment => comment.body?.includes(GITHUB_COMMENT_MARKER))12 const hasExistingComment = pull.body?.includes(GITHUB_COMMENT_MARKER)13 const commentBody = `14<!-- Do NOT delete these comments. They are used by Live Github to track this Pull Request -->15<!-- ${GITHUB_COMMENT_MARKER} -->16-----17LiveGithub is listening to this PR :ear:18LiveGithub can create a Slack Channel specifcally for this PR. When it's created all the reviewers will be invited to the channel, and it will be archived when the PR closes.19The channel name will be \`${channelName}\`.20[Click Here to Create and Open the channel](${openSlackUrl})21`.trim()22 if (existingManagedComment) {23 try {24 await octokit.rest.issues.deleteComment({25 owner: process.env.GITHUB_OWNER!,26 repo: pull.base.repo.name,27 comment_id: existingManagedComment.id,28 })29 console.log(`â
PR#${pull.number}: Successfully removed legacy comment`)30 } catch (error) {31 console.log(`â PR#${pull.number}: Failed to remove legacy comment`)32 console.log(error)33 throw error34 }35 }36 if (!hasExistingComment && pull.body) {37 try {38 await octokit.rest.pulls.update({39 owner: process.env.GITHUB_OWNER!,40 repo: pull.base.repo.name,41 pull_number: pull.number,42 body: pull.body + '\n\n' + commentBody,43 })44 console.log(`â
PR#${pull.number}: Successfully added initial comment`)45 } catch (error) {46 console.log(`â PR#${pull.number}: Failed to add initial comment`)47 console.log(error)48 throw error49 }50 }51}52export const addComment = async (githubApp: GithubApp, command: SlashCommand, say: SayFn): Promise<void> => {53 const octokit = await githubApp.getInstallationOctokit(parseInt(process.env.GITHUB_INSTALLATION_ID!))54 const splitName = command.channel_name.split('-')55 const repoName = splitName.slice(2).join('-')56 const pullNumber = parseInt(splitName[1])57 const githubBody = `**${command.user_name}** says:\n${command.text}`58 const slackBody = `*${command.user_name}* says:\n${command.text}\n_Comment posted to Github_`59 try {60 await octokit.rest.issues.createComment({61 owner: process.env.GITHUB_OWNER!,62 repo: repoName,63 issue_number: pullNumber,64 body: githubBody,65 })66 say(slackBody)67 console.log(`â
Channel ${command.channel_name}: Successfully added a comment`)68 } catch (error) {69 console.log(`â Channel ${command.channel_name}: Failed to add a comment`)70 console.log(error)71 throw error72 }73}74export const getApproveReview = async (githubApp: GithubApp, pull: PullRequest) => {75 try {76 const octokit = await githubApp.getInstallationOctokit(parseInt(process.env.GITHUB_INSTALLATION_ID!))77 const reviewComments = await octokit.rest.pulls.get({78 owner: process.env.GITHUB_OWNER!,79 repo: pull.base.repo.name,80 pull_number: pull.number,81 })82 console.log(reviewComments.data)83 console.log(`â
PR#${pull.number}: Successfully fetched reviews`)84 return reviewComments85 } catch (error) {86 console.log(`â PR#${pull.number}: Failed to fetch reviews`)87 console.log(error)88 throw error89 }90}91export const getReviewComments = async (githubApp: GithubApp, pull: Pick<PullRequest, 'number' | 'base'>) => {92 try {93 const octokit = await githubApp.getInstallationOctokit(parseInt(process.env.GITHUB_INSTALLATION_ID!))94 const reviewComments = await octokit.rest.pulls.listReviewComments({95 owner: process.env.GITHUB_OWNER!,96 repo: pull.base.repo.name,97 pull_number: pull.number,98 })99 console.log(`â
PR#${pull.number}: Successfully fetched review comments`)100 return reviewComments.data101 } catch (error) {102 console.log(`â PR#${pull.number}: Failed to fetch review comments`)103 console.log(error)104 throw error105 }106}107export const getPullComments = async (githubApp: GithubApp, pull: Pick<PullRequest, 'number' | 'base'>) => {108 const octokit = await githubApp.getInstallationOctokit(parseInt(process.env.GITHUB_INSTALLATION_ID!))109 const response = await octokit.rest.issues.listComments({110 owner: process.env.GITHUB_OWNER!,111 repo: pull.base.repo.name,112 issue_number: pull.number,113 })114 return response.data115}116export const getPullRequest = async (githubApp: GithubApp, repoName: string, pullNumber: number) => {117 const octokit = await githubApp.getInstallationOctokit(parseInt(process.env.GITHUB_INSTALLATION_ID!))118 const response = await octokit.rest.pulls.get({119 owner: process.env.GITHUB_OWNER!,120 repo: repoName,121 pull_number: pullNumber,122 })123 return response.data124}125export const postReviewComentReply = async (126 githubApp: GithubApp,127 pull: Pick<PullRequest, 'number' | 'base'>,128 comment_id: number,129 reply: string,130) => {131 const octokit = await githubApp.getInstallationOctokit(parseInt(process.env.GITHUB_INSTALLATION_ID!))132 return octokit.rest.pulls.createReplyForReviewComment({133 owner: process.env.GITHUB_OWNER!,134 repo: pull.base.repo.name,135 pull_number: pull.number,136 comment_id,137 body: reply,138 })...
Using AI Code Generation
1const { getInstallationOctokit } = require("@argos-ci/github");2const { getInstallationOctokit } = require("@argos-ci/github");3const { getInstallationOctokit } = require("@argos-ci/github");4const { getInstallationOctokit } = require("@argos-ci/github");5const { getInstallationOctokit } = require("@argos-ci/github");6const { getInstallationOctokit } = require("@argos-ci/github");7const { getInstallationOctokit } = require("@argos-ci/github");8const { getInstallationOctokit } = require("@argos-ci/github");9const { getInstallationOctokit } = require("@argos-ci/github");10const { getInstallationOctokit } = require("@argos-ci/github");11const { getInstallationOctokit } = require("@argos-ci/github");12const { getInstallationOctokit } = require("@argos-ci/github");13const { getInstallationOctokit } = require("@argos-ci/github");14const { getInstallationOctokit } = require("@argos-ci/github");15const { getInstallationOctokit } = require("@argos-ci/github");
Using AI Code Generation
1const { getInstallationOctokit } = require("@argos-ci/github");2const octokit = await getInstallationOctokit({ installationId: 1234 });3const { getInstallationOctokit } = require("@argos-ci/github");4const octokit = await getInstallationOctokit({ installationId: 1234 });5const { getInstallationOctokit } = require("@argos-ci/github");6const octokit = await getInstallationOctokit({ installationId: 1234 });
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!!