Skip to content

Commit

Permalink
feat(#13): --graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Oct 2, 2024
1 parent 1d3b297 commit e846b54
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 94 deletions.
98 changes: 5 additions & 93 deletions src/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,98 +21,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
const graph = `query ($searchQuery: String!, $first: Int, $after: String) {
search(query: $searchQuery, type: REPOSITORY, first: $first, after: $after) {
repositoryCount
nodes {
... on Repository {
nameWithOwner
description
defaultBranchRef {
name
}
object(expression: "HEAD:.github/workflows/") {
... on Tree {
entries {
name
object {
... on Blob {
byteSize
}
}
}
}
}
primaryLanguage {
name
}
createdAt
refs(refPrefix: "refs/heads/") {
totalCount
}
defaultBranchRef {
name
target {
repository {
object(expression: "HEAD:README.md") {
... on Blob {
text
}
}
}
... on Commit {
history(first: 1) {
totalCount
edges {
node {
committedDate
}
}
}
}
}
}
mentionableUsers {
totalCount
}
latestRelease {
createdAt
}
releases(first:1) {
edges {
node {
id
}
}
totalCount
}
stargazerCount
forkCount
pullRequests {
totalCount
}
issues(states: [OPEN]) {
totalCount
}
licenseInfo {
spdxId
}
repositoryTopics(first: 10) {
edges {
node {
topic {
name
}
}
}
}
}
}
pageInfo {
endCursor
hasNextPage
}
}
}`;

const fs = require('fs');
const graph = (path) => {
return fs.readFileSync(path, "utf-8");
};

module.exports = graph;
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const startDate = argv.start || '2008-01-01';
const endDate = argv.end || now;
const dateType = argv.date || 'created';
const print = argv.json || false;
const gpath = argv.graphql || "ghminer.graphql";

let tokens;
if (argv.tokens) {
Expand Down Expand Up @@ -96,7 +97,7 @@ async function fetchResultsBatch(
Authorization: `Bearer ${nextToken()}`
}
});
const data = await client.request(query, {
const data = await client.request(query(gpath), {
searchQuery,
first: batchsize,
after: cursor
Expand Down
39 changes: 39 additions & 0 deletions test/graph.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 Aliaksei Bialiauski
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
const assert = require('assert');
const graph = require('../src/graph');

describe('Test case for graph.js', function() {
it('reads GraphQL query from file', function() {
const query = graph(
'test/resources/query.graphql'
);
const expected = 'query ($searchQuery: String!, $first: Int, $after: String) {}\n';
assert.equal(
query,
expected,
`found query ${query} does not match with expected ${expected}`
);
});
});
1 change: 1 addition & 0 deletions test/resources/query.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
query ($searchQuery: String!, $first: Int, $after: String) {}

0 comments on commit e846b54

Please # to comment.