Best JavaScript code snippet using argos
RepositoryService.ts
Source:RepositoryService.ts
1import axios from 'axios';2import { differenceInDays, format } from 'date-fns';3import { StandardDeviationService } from './StandardDeviationService';4import {5 noTratedIssuesInterface, repositoryIssueResponseInterface,6 repositoryIssuesInterface,7} from '../interfaces';8import { RepositoryRepository } from '../repositories';9import { stateIssuesEnum } from '../utils/enums/stateIssues';10import { PagesService } from '.';11import { AppError } from '../errors';12const API_GITHUB_BASE_URL = process.env.GITHUB_API_BASE_URL;13const API_GITHUB_TOKEN = process.env.GITHUB_AUTH_TOKEN;14class RepositoryService {15 async searchIssues(repository: repositoryIssuesInterface) {16 const standardDeviationService = new StandardDeviationService();17 const pagesService = new PagesService();18 const { owner, projectName } = repository;19 const perPage: number = 100;20 const openIssues: Array<number> = [];21 let totalTimeOfOpenIssues: number = 0;22 const {23 data: repoResponse,24 } = await this.getRepositoryDetails(owner, projectName);25 if (repoResponse && repoResponse.open_issues) {26 const totalOpenIssues = repoResponse.open_issues;27 const pages = pagesService28 .createPagesArrayFromLimitNumber(Math.round(totalOpenIssues / perPage));29 await Promise.all(30 pages.map(async (item) => {31 const {32 data: issuesResponse,33 } = await this.getIssuesDetails(owner, projectName, item, perPage, stateIssuesEnum.OPEN);34 if (issuesResponse && issuesResponse.length) {35 totalTimeOfOpenIssues += this.issuesTimeOpenCalculate(issuesResponse, openIssues);36 }37 }),38 );39 await this.updateOrCreateDataBaseRegister(owner, projectName);40 }41 const openIssuesAverage = totalTimeOfOpenIssues / openIssues.length;42 const openIssuesDeviation = standardDeviationService43 .calculateStandardDeviation(openIssuesAverage, openIssues);44 const response = {45 repository: projectName,46 open_issues: openIssues.length,47 open_issues_average_age: openIssuesAverage,48 open_issues_std_average: openIssuesDeviation,49 };50 return response;51 }52 async issuesStats() {53 const repositoryRepository = new RepositoryRepository();54 const pagesService = new PagesService();55 const activeRepositories = await repositoryRepository.indexActive();56 const noTratedStats: any = {};57 if (activeRepositories && activeRepositories.length) {58 for (const repository of activeRepositories) {59 const { owner, name: projectName } = repository;60 const perPage: number = 100;61 noTratedStats[projectName] = {};62 const {63 data: repoResponse,64 } = await this.getRepositoryDetails(owner, projectName);65 if (repoResponse && repoResponse.open_issues) {66 const totalOpenIssues = repoResponse.open_issues;67 const pages = pagesService68 .createPagesArrayFromLimitNumber(Math.round(totalOpenIssues / perPage));69 await Promise.all(70 pages.map(async (item) => {71 const {72 data: issuesResponse,73 } = await this.getIssuesDetails(74 owner, projectName, item, perPage, stateIssuesEnum.ALL,75 );76 if (issuesResponse && issuesResponse.length) {77 noTratedStats[projectName] = this.mountNotratedIssues(issuesResponse);78 }79 }),80 );81 }82 }83 }84 const data = {85 repositories: this.createArrayRepositoriesStats(noTratedStats),86 };87 return data;88 }89 // =====> PRIVATE METHODOS <===== //90 private mountNotratedIssues(91 issuesResponse: Array<repositoryIssueResponseInterface>,92 ) {93 const noTratedStats: noTratedIssuesInterface = {94 issues: {},95 };96 for (const issue of issuesResponse) {97 const { state, created_at: createdAt } = issue;98 const date = format(new Date(createdAt), 'yyyy/MM/dd');99 const issueExists = noTratedStats.issues[date];100 if (!issueExists) {101 noTratedStats.issues[date] = {102 open: 0,103 closed: 0,104 };105 }106 noTratedStats.issues[date][state] += 1;107 }108 return noTratedStats;109 }110 private createArrayRepositoriesStats(noTratedStats: noTratedIssuesInterface) {111 const convertedStats = Object.entries(noTratedStats);112 const tratedStats = [];113 for (const [repository, statsValue] of convertedStats) {114 const { issues: noTratedIssues } = statsValue;115 const convertedIssues: Array<any> = Object.entries(noTratedIssues);116 const issues = [];117 for (const [date, issueValue] of convertedIssues) {118 const { open, closed } = issueValue;119 issues.push({120 created_at: date,121 open,122 closed,123 });124 }125 tratedStats.push({126 repository,127 issues,128 });129 }130 return tratedStats;131 }132 private issuesTimeOpenCalculate(133 responseData: Array<repositoryIssueResponseInterface>, openIssues: Array<number>,134 ) {135 let totalTimeOfOpenIssues: number = 0;136 for (const data of responseData) {137 const { created_at: createdAt } = data;138 const difference = this.calculateDifferenceInDays(new Date(createdAt));139 totalTimeOfOpenIssues += difference;140 openIssues.push(difference);141 }142 return totalTimeOfOpenIssues;143 }144 private async getIssuesDetails(145 owner: string, projectName: string, page: number,146 perPage: number, state: stateIssuesEnum,147 ) {148 try {149 const data = await axios.get(150 `${API_GITHUB_BASE_URL}/repos/${owner}/${projectName}/issues`,151 {152 params: { page, per_page: perPage, state },153 headers: { Authorization: `token ${API_GITHUB_TOKEN}` },154 },155 );156 return data;157 } catch (error) {158 const code = error?.response?.status || 500;159 const message = error?.response?.statusText || 'Internal server error.';160 throw new AppError(message, code);161 }162 }163 private async getRepositoryDetails(owner: string, projectName: string) {164 try {165 const data = await axios.get(166 `${API_GITHUB_BASE_URL}/repos/${owner}/${projectName}`,167 {168 headers: { Authorization: `token ${API_GITHUB_TOKEN}` },169 },170 );171 return data;172 } catch (error) {173 const code = error?.response?.status || 500;174 const message = error?.response?.statusText || 'Internal server error.';175 throw new AppError(message, code);176 }177 }178 private async updateOrCreateDataBaseRegister(owner: string, projectName: string) {179 const repositoryRepository = new RepositoryRepository();180 const repositoryExists = await repositoryRepository.showByName(projectName);181 if (repositoryExists) {182 const { _id: id } = repositoryExists;183 await repositoryRepository.incrementSearchCountById(id);184 }185 else {186 await repositoryRepository.create(owner, projectName);187 }188 }189 private calculateDifferenceInDays(compareDate: Date) {190 return differenceInDays(new Date(), compareDate);191 }192}193export {194 RepositoryService,...
postRequest.ts
Source:postRequest.ts
1import axios from 'axios';2import { CrawlInformation } from './CrawlInformation';3import { ActiveRespository } from './activeRepository';4import { StarredRespository } from './starredRepository';5import { ActiveUser } from './activeUser';6/**7 * Communicates with GitHub GraphQL API and processes responses.8 */9export abstract class postRequest {10 /**11 * Set authorization headers for http requests.12 */13 constructor() {14 axios.defaults.headers.common['Authorization'] = 'Bearer ' + '8e5418de6adba926f72e9dd91cfa5cd0d4042664';15 }16 /**17 * 18 * @param queryContent GraphQL query that is sent to the GitHub API19 * @param callback function that handles the returned response20 * @param crawlInformation 'metadata' passed to callback function for response handling21 */22 async startPost(queryContent: string, callback: any, crawlInformation: CrawlInformation) {23 return axios.post('https://api.github.com/graphql', {24 query: queryContent,25 })26 .then(async function (response) {27 // 'response.data.data' accesses the relevant data in the nested JSON28 return callback(response.data.data, crawlInformation);29 })30 .catch(function (error) {31 console.log(error);32 });33 }34 /**35 * 36 * @param response Data that is returned from API request37 * @param crawlInformation 'Metadata' used for response handling38 * Processes responses returned from GitHub API requests. Returns processed data.39 * Walks through nested JSON responses using according keys to access relevant data.40 */41 processResponse(response: any, crawlInformation: CrawlInformation) {42 switch (crawlInformation) {43 case CrawlInformation.SearchIfOrganizationValid:44 return response.organization;45 case CrawlInformation.SearchMostActiveUsersCommits:46 var commitAmount: number = 0;47 // For each user, add up all commits from all repositories that the user has committed to48 for (let commitInfo of response.user.repositoriesContributedTo.nodes) {49 if (commitInfo.defaultBranchRef != null) {50 commitAmount = + commitInfo.defaultBranchRef.target.history.totalCount;51 }52 }53 return new ActiveUser(response.user.name, response.user.login, response.user.id, commitAmount, response.user.repositoriesContributedTo.totalCount);54 case CrawlInformation.SearchMostActiveUserInformation:55 var activeUsers: Array<ActiveUser> = new Array<ActiveUser>();56 for (let userInfo of response.organization.members.nodes) {57 activeUsers.push(new ActiveUser(userInfo.name, userInfo.login, userInfo.id, 0, userInfo.repositoriesContributedTo));58 }59 return activeUsers;60 case CrawlInformation.SearchMostStarRepos:61 var starredRepositories: Array<StarredRespository> = new Array<StarredRespository>();62 for (let repoInfo of response.search.edges) {63 starredRepositories.push(new StarredRespository(repoInfo.node.name, repoInfo.node.description, repoInfo.node.stargazers.totalCount));64 }65 return starredRepositories;66 case CrawlInformation.SearchMostActiveRepos:67 var activeRepositories: Array<ActiveRespository> = new Array<ActiveRespository>();68 for (let repoInfo of response.search.edges) {69 activeRepositories.push(new ActiveRespository(repoInfo.node.name, repoInfo.node.description, repoInfo.node.defaultBranchRef.target.history.totalCount));70 }71 sortActiveRepositories(activeRepositories);72 return activeRepositories;73 default:74 return response;75 }76 }77}78function sortActiveRepositories(activeRespositories: Array<ActiveRespository>) {79 activeRespositories.sort((a, b) => {80 if (a.getCommitAmount() == b.getCommitAmount()) {81 return 0;82 } else {83 if (a.getCommitAmount() > b.getCommitAmount()) {84 return -1;85 }86 else if (a.getCommitAmount() < b.getCommitAmount()) {87 return 1;88 }89 }90 })...
Repositories.js
Source:Repositories.js
1/* eslint-disable react/no-unescaped-entities */2import * as React from "react";3import { gql } from "graphql-tag";4import { x } from "@xstyled/styled-components";5import { Query } from "../../containers/Apollo";6import {7 Container,8 SecondaryTitle,9 Link,10 Loader,11} from "@argos-ci/app/src/components";12import config from "../../config";13import { useParams } from "react-router-dom";14import {15 ActiveRepositoryCard,16 InactiveRepositoryCard,17 NoRepositoryCard,18 OwnerRepositoryCardFragment,19} from "./RepositoryCard";20import { NotFound } from "../NotFound";21import { OwnerTabs } from "./OwnerTabs";22import { Helmet } from "react-helmet";23import { LinkExternalIcon } from "@primer/octicons-react";24const getRepositoryUrl = (owner, repository) =>25 `/${owner.login}/${repository.name}`;26export function OwnerRepositories() {27 const { ownerLogin } = useParams();28 return (29 <Container>30 <Helmet>31 <title>{ownerLogin}</title>32 </Helmet>33 <Query34 query={gql`35 query OWNER_REPOSITORIES_QUERY($login: String!) {36 owner(login: $login) {37 id38 name39 login40 repositories {41 id42 enabled43 name44 ...OwnerRepositoryCardFragment45 }46 }47 }48 ${OwnerRepositoryCardFragment}49 `}50 variables={{ login: ownerLogin }}51 fetchPolicy="no-cache"52 fallback={<Loader />}53 >54 {({ owner }) => {55 if (!owner) return <NotFound />;56 const activeRepositories = owner.repositories.filter(57 ({ enabled }) => enabled58 );59 const inactiveRepositories = owner.repositories.filter(60 ({ enabled }) => !enabled61 );62 return (63 <>64 <OwnerTabs />65 <x.div display="flex" flexDirection="column">66 <SecondaryTitle id="active-repositories">67 Active repositories68 </SecondaryTitle>69 <x.div display="flex" flexDirection="column" gap={4}>70 {activeRepositories.length === 0 ? (71 <NoRepositoryCard />72 ) : (73 activeRepositories.map((repository) => (74 <ActiveRepositoryCard75 key={repository.id}76 repository={repository}77 url={getRepositoryUrl(owner, repository)}78 />79 ))80 )}81 </x.div>82 <SecondaryTitle id="inactive-repositories" mt={8}>83 Inactive repositories84 </SecondaryTitle>85 <x.div display="flex" flexDirection="column" gap={3}>86 {inactiveRepositories.length === 0 ? (87 <NoRepositoryCard />88 ) : (89 inactiveRepositories.map((repository) => (90 <InactiveRepositoryCard91 key={repository.id}92 repository={repository}93 url={getRepositoryUrl(owner, repository)}94 />95 ))96 )}97 </x.div>98 </x.div>99 <x.div mt={14}>100 Don't see your repo? Click here to{" "}101 <Link href={config.get("github.appUrl")} target="_blank">102 manage access restrictions on GitHub <LinkExternalIcon />103 </Link>104 </x.div>105 </>106 );107 }}108 </Query>109 </Container>110 );...
Using AI Code Generation
1var argosRepo = require('argos-repo');2argosRepo.activeRepositories(function(err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var argosRepo = require('argos-repo');10argosRepo.getRepository('test', function(err, data) {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var argosRepo = require('argos-repo');18argosRepo.createRepository('test', function(err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var argosRepo = require('argos-repo');26argosRepo.deleteRepository('test', function(err, data) {27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var argosRepo = require('argos-repo');34argosRepo.updateRepository('test', 'test2', function(err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var argosRepo = require('argos-repo');42argosRepo.getRepositoryFiles('test', function(err, data) {43 if (err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49var argosRepo = require('argos-repo');50argosRepo.getRepositoryFile('test', 'test.txt', function(err, data) {51 if (err) {52 console.log(err);53 } else {54 console.log(data);55 }56});57var argosRepo = require('argos-re
Using AI Code Generation
1var argosRepo = require('argos-repo');2var repo = new argosRepo();3repo.activeRepositories(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});
Using AI Code Generation
1var argosRepo = require('argos-repo');2var activeRepos = argosRepo.activeRepositories();3console.log(activeRepos);4var argosRepo = require('argos-repo');5var allRepos = argosRepo.allRepositories();6console.log(allRepos);7var argosRepo = require('argos-repo');8var allRepos = argosRepo.allRepositories();9console.log(allRepos);10var argosRepo = require('argos-repo');11var repo = argosRepo.getRepository('argos-saleslogix');12console.log(repo);13var argosRepo = require('argos-repo');14var repo = argosRepo.getRepository('argos-saleslogix');15console.log(repo);16var argosRepo = require('argos-repo');17var repo = argosRepo.getRepository('argos-saleslogix');18console.log(repo);19var argosRepo = require('argos-repo');20var repo = argosRepo.getRepository('argos-saleslogix');21console.log(repo);22var argosRepo = require('argos-repo');23var repo = argosRepo.getRepository('argos-saleslogix');24console.log(repo);25var argosRepo = require('argos-repo');26var repo = argosRepo.getRepository('argos-saleslogix');27console.log(repo);28var argosRepo = require('argos-repo');29var repo = argosRepo.getRepository('argos-saleslogix');30console.log(repo);
Using AI Code Generation
1const argosRepo = require('argos-repo');2async function main() {3 const activeRepos = await argosRepo.activeRepositories();4 console.log(activeRepos);5}6main();
Using AI Code Generation
1var repoListService = require('argos-sdk/src/Services/RepoListService');2repoListService.activeRepositories().then(function(repos) {3 console.log(repos);4});5### RepoListService.activeRepositoryNames()6var repoListService = require('argos-sdk/src/Services/RepoListService');7repoListService.activeRepositoryNames().then(function(repos) {8 console.log(repos);9});10### RepoListService.allRepositories()11var repoListService = require('argos-sdk/src/Services/RepoListService');12repoListService.allRepositories().then(function(repos) {13 console.log(repos);14});15### RepoListService.allRepositoryNames()16var repoListService = require('argos-sdk/src/Services/RepoListService');17repoListService.allRepositoryNames().then(function(repos) {18 console.log(repos);19});20### RepoListService.addRepository(repository)21var repoListService = require('argos-sdk/src/Services/RepoListService');22repoListService.addRepository('newrepo');23### RepoListService.removeRepository(repository)24var repoListService = require('argos-sdk/src/Services/RepoListService');25repoListService.removeRepository('newrepo');
Using AI Code Generation
1const activeRepo = require('argos-repo');2activeRepo.activeRepositories().then(function(activeRepos) {3 console.log(activeRepos);4});5const activeRepo = require('argos-repo');6activeRepo.getBranches().then(function(branches) {7 console.log(branches);8});9const activeRepo = require('argos-repo');10activeRepo.getCommits().then(function(commits) {11 console.log(commits);12});13const activeRepo = require('argos-repo');14activeRepo.getReleases().then(function(releases) {15 console.log(releases);16});17const activeRepo = require('argos-repo');18activeRepo.getTags().then(function(tags) {19 console.log(tags);20});21const activeRepo = require('argos-repo');22activeRepo.getRepos().then(function(repos) {23 console.log(repos);24});25const activeRepo = require('argos-repo');26activeRepo.getRepo().then(function(repo) {27 console.log(repo);28});29const activeRepo = require('argos-repo');30activeRepo.getRepoTags().then(function(repoTags) {31 console.log(repoTags);32});33const activeRepo = require('argos-repo');34activeRepo.getRepoCommits().then(function(repoCommits) {35 console.log(repoCommits);36});37const activeRepo = require('argos-repo');38activeRepo.getRepoBranches().then(function(repoBranches) {39 console.log(repoBranches);40});
Using AI Code Generation
1const sdk = require('argos-sdk');2const activeRepositories = sdk.activeRepositories();3console.log(activeRepositories);4### `sdk.getRepositoryMetadata(repositoryName)`5const sdk = require('argos-sdk');6const repositoryMetadata = sdk.getRepositoryMetadata('repo1');7console.log(repositoryMetadata);8### `sdk.getRepositoryConfig(repositoryName)`9const sdk = require('argos-sdk');10const repositoryConfig = sdk.getRepositoryConfig('repo1');11console.log(repositoryConfig);12### `sdk.getRepositoryDependencies(repositoryName)`13const sdk = require('argos-sdk');14const repositoryDependencies = sdk.getRepositoryDependencies('repo1');15console.log(repositoryDependencies);
Using AI Code Generation
1var argosy = require('argosy')2var argosy = argosy()3var pattern = {role: 'user', cmd: 'activeRepositories'}4argosy.act(pattern, function (err, results) {5 if (err) {6 console.log('Error: ' + err)7 } else {8 console.log('Results: ' + results)9 }10})11argosy.listen(3000)12var argosy = require('argosy')13var argosy = argosy()14var pattern = {role: 'user', cmd: 'activeRepositories'}15argosy.accept(pattern, function (msg, cb) {16 cb(null, 'repo1, repo2, repo3')17})18argosy.listen(3000)
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!!