-
Notifications
You must be signed in to change notification settings - Fork 0
feat: github pr search #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| REPO_OWNER="Git-Commit-Show" | ||
| GITHUB_PERSONAL_TOKEN="ghp_adsfdsf32sdfasdfcdcsdfsdf23sfasdf1" | ||
| GITHUB_PERSONAL_TOKEN="ghp_adsfdsf32sdfasdfcdcsdfsdf23sfasdf1" | ||
| APERTURE_SERVICE_ADDRESS="my.app.fluxninja.com:443" | ||
| APERTURE_API_KEY="4dsfs323db7dsfsde310ca6dsdf12sfr4" |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @file Functions to analyze and archive meaningful github contributors data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @file Functions to analyze and archive meaningful github data such as contributors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @example To archive contributors leaderboard data in csv file, run `node contributors.js` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -210,4 +210,55 @@ export async function archiveContributorsLeaderboard(owner=REPO_OWNER, options) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| writeContributorLeaderboardToFile(contributors); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ghHandles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Search pull requests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {string} query | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {Object} options Additional options e.g. { pageNo: 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export async function searchPullRequests(query, options) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let pageNo = (options && options.pageNo) ? options.pageNo : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(options && options.GITHUB_PERSONAL_TOKEN){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GITHUB_REQUEST_OPTIONS.headers["Authorization"] = "token "+options.GITHUB_PERSONAL_TOKEN; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let queryString = encodeURIComponent(''+query+'type:pr') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let url = `https://api.github.com/search/issues?q=${queryString}&per_page=100&page=${pageNo}&sort=${options.sort || 'created'}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { res, data } = await makeRequestWithRateLimit('GET', url, Object.assign({},GITHUB_REQUEST_OPTIONS)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("PR search request finished"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('HTTP status: ', res.statusCode); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // console.log(data) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let searchResultObject = JSON.parse(data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return searchResultObject; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Get all search results, not just one page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {string} query | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {Object} options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {Object} options.maxResults limit maximum results | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export async function recursiveSearchPullRequests(query, options){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let prList = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let pageNo = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let maxResults = options.maxResults || 10000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let searchResultObject = await searchPullRequests(query, Object.assign({ pageNo: pageNo }, options)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Iterate over results if there are more results expected by the user | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(!searchResultObject || !searchResultObject.items || !searchResultObject.items.length<1 || maxResults < 100){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return prList; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| prList.push(searchResultObject.items); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let incomplete_results = searchResultObject.incomplete_results; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while(prList.length < searchResultObject.total_count && !incomplete_results){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pageNo++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let nextPageSearchResultObject = await searchPullRequests(query, { pageNo: pageNo } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| prList.push(...nextPageSearchResultObject.items); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| incomplete_results = nextPageSearchResultObject.incomplete_results; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (err) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("Some issue in recursive search for pull requests") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("Found "+prList.length +" PRs"+" for "+query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return prList; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the - if(!searchResultObject || !searchResultObject.items || !searchResultObject.items.length<1 || maxResults < 100){
+ if(!searchResultObject || !searchResultObject.items || !(searchResultObject.items.length >= 1) || maxResults < 100){Additionally, the function does not handle the case where Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing newline at the end of the file. + \nCommittable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import * as contributorsLib from './contributors.js'; | ||
| import * as contributorsLib from './github.js'; | ||
|
|
||
| /** | ||
| * Bundling all APIs together | ||
|
Comment on lines
+1
to
4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Final response to the review comment: The
Analysis chain
Verify that the Given the warning from ast-grep and the possibility that the function could be exported in a different manner than the pattern I used, I will write a new script using ripgrep (rg) to search for the string Before concluding, I will verify the presence of the Scripts ExecutedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for the export of `archiveContributorsLeaderboard` in `github.js`.
ast-grep --lang javascript --pattern $'export function archiveContributorsLeaderboard($_, $_)'
Length of output: 440 Script: #!/bin/bash
# Search for the string 'archiveContributorsLeaderboard' in 'github.js' to verify if it is present and exported.
rg 'archiveContribitorsLeaderboard' --files-with-matches
Length of output: 56 Script: #!/bin/bash
# Verify the presence of the `github.js` file in the codebase.
fd 'github.js'
Length of output: 24 |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export const PR_SEARCH_QUERY = "gitcommitshow"; | ||
| export const VALID_SEARCH_RESULT_SAMPLE = { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,17 @@ | ||
| import { expect, assert } from "chai"; | ||
| import * as contributorsLib from "../contributors.js"; | ||
| import * as githubApi from "../github.js"; | ||
|
|
||
| import * as contributorsFixture from './fixtures/contributors.fixture.js'; | ||
| import * as pullRequestsFixture from './fixtures/pullRequests.fixture.js'; | ||
|
|
||
| describe('contibutors.js', function() { | ||
| describe('github.js', function() { | ||
|
|
||
| /** GitHub contrbutors test --START-- */ | ||
|
|
||
| describe.skip('#getAllRepos('+contributorsFixture.VALID_REPO_OWNER+');', async function() { | ||
| it('should return the repos owned by '+contributorsFixture.VALID_REPO_OWNER, async function() { | ||
| this.timeout(100000); | ||
| let repos = await contributorsLib.getAllRepos(contributorsFixture.VALID_REPO_OWNER); | ||
| let repos = await githubApi.getAllRepos(contributorsFixture.VALID_REPO_OWNER); | ||
| assert.isNotNull(repos); | ||
| expect(repos).to.be.an('array', 'Not an array') | ||
| expect(repos.length).to.be.greaterThanOrEqual(contributorsFixture.REPO_COUNT_MIN); | ||
|
|
@@ -21,7 +22,7 @@ describe('contibutors.js', function() { | |
| describe.skip('#getRepoContributors('+contributorsFixture.VALID_REPO+');', async function() { | ||
| it('should return the repo contribuors', async function() { | ||
| this.timeout(100000); | ||
| let contributors = await contributorsLib.getRepoContributors(contributorsFixture.VALID_REPO) | ||
| let contributors = await githubApi.getRepoContributors(contributorsFixture.VALID_REPO) | ||
| assert.isNotNull(contributors); | ||
| expect(contributors).to.be.an('array', 'Not an array') | ||
| expect(contributors.length).to.be.greaterThanOrEqual(contributorsFixture.REPO_CONTRIBUTOR_COUNT_MIN); | ||
|
|
@@ -32,12 +33,41 @@ describe('contibutors.js', function() { | |
| describe.skip('#getAllContributors('+contributorsFixture.VALID_REPO_OWNER+');', async function() { | ||
| it('should return all contributors across different repositories of REPO_OWNER', async function() { | ||
| this.timeout(100000); | ||
| let contributors = await contributorsLib.getAllContributors(contributorsFixture.VALID_REPO_OWNER); | ||
| let contributors = await githubApi.getAllContributors(pullRequestsFixture.QUERY); | ||
| assert.isNotNull(contributors); | ||
| expect(contributors).to.be.an('array', 'Not an array') | ||
| expect(contributors.length).to.be.greaterThanOrEqual(contributorsFixture.ALL_REPO_CONTRIBUTOR_COUNT_MIN); | ||
| expect(contributors[0]).to.include.all.keys('login','id','node_id','avatar_url','gravatar_id','url','html_url','followers_url','following_url','gists_url','starred_url','subscriptions_url','organizations_url','repos_url','events_url','received_events_url','type','site_admin','contributions'); | ||
| }) | ||
| }) | ||
|
|
||
| // OCK PR search test | ||
| describe.skip('#OCK.github.searchPullRequests(query, options);', async function() { | ||
| it('should start the task of archiving contributors for REPO_OWNER', async function() { | ||
|
||
| this.timeout(100000); | ||
| let prSearchResults = await githubApi.searchPullRequests(pullRequestsFixture.PR_SEARCH_QUERY); | ||
| assert.isNotNull(prSearchResults, "No PR search results returned"); | ||
| expect(prSearchResults).to.be.an('object'); | ||
| expect(prSearchResults).to.have.all.keys('items', 'total_count', 'incomplete_results'); | ||
| expect(prSearchResults.items).to.be.an('array'); | ||
| expect(prSearchResults.items).to.have.lengthOf.at.least(1); | ||
| expect(prSearchResults.items[0]).to.include.all.keys('title', 'html_url', 'state', 'user', 'draft', 'repository_url', 'comments', 'comments_url', 'assignees', 'created_at', 'closed_at'); | ||
| }) | ||
| }) | ||
|
||
|
|
||
| // OCK PR search test | ||
| describe('#OCK.github.searchPullRequests(query, options);', async function() { | ||
| it('should start the task of archiving contributors for REPO_OWNER', async function() { | ||
| this.timeout(100000); | ||
| let prResults = await githubApi.recursiveSearchPullRequests("test", { maxResults: 198}); | ||
| assert.isNotNull(prResults, "No PR search results returned"); | ||
| expect(prResults).to.be.an('array'); | ||
| expect(prResults).to.have.lengthOf.at.least(198); | ||
| expect(prResults).to.have.lengthOf.at.most(200); | ||
| expect(prResults[0]).to.include.all.keys('title', 'html_url', 'state', 'user', 'draft', 'repository_url', 'comments', 'comments_url', 'assignees', 'created_at', 'closed_at'); | ||
| }) | ||
| }) | ||
|
|
||
|
|
||
|
|
||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.