Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Issue 51: Adding updatedAt and labels to the output #53

Merged
merged 4 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,50 @@ The input file is a JSON file in the format:
### Output File Format

The output file is a JSON file in the format:

- (We'll add a definition of the format later.
For now, you can look at examples/output.json after running the app)
```javascript
{
"repository/name": [
{
"title": "Issue Title 1",
"createdAt": "2020-10-16T01:07:36Z",
"repositoryNameWithOwner": "repository/name",
"url": "https://github.com/repository/name/issues/65",
"updatedAt": "2020-10-16T01:07:36Z",
"labels": [
"Hacktoberfest",
"good first issue"
]
},
{
"title": "Issue Title 2",
"createdAt": "2020-10-12T22:37:17Z",
"repositoryNameWithOwner": "repository/name",
"url": "https://github.com/repository/name/issues/58",
"updatedAt": "2020-10-12T22:37:17Z",
"labels": [
"Hacktoberfest",
"good first issue"
]
}
],
"respository/second_name": [
{
"title": "Issue 102",
"createdAt": "2020-10-03T13:16:58Z",
"repositoryNameWithOwner": "respository/second_name",
"url": "https://github.com/respository/second_name/issues/12137",
"updatedAt": "2020-10-03T13:16:58Z",
"labels": [
"claimed",
"good first issue",
"i: enhancement"
]
}
],
}
```

Please note that only the first 100 labels per issue will be fetched. If a single issue has over 100 labels, these will be excluded without any errors or warnings.

## Token

Expand Down Expand Up @@ -135,6 +176,8 @@ Run `npm run build` to compile the code to Javascript.

Run `node dist/examples/runFasterCode.js` (to use GraphQL) or `node dist/examples/runOldCode.ts` (to use REST calls), to run the example program. It requires internet access, since it calls the GitHub API. It will take a couple minutes to complete. Some of the output includes the word "ERROR", so don't panic.

Ensure to lint your code by running `npm run lint` before submitting any code for review. `npm run lint:fix` will automatically fix any errors.

## Local testing of the npm packaging

You should have local copies of both the oss-mariner project and the project that will include it.
Expand Down
21 changes: 20 additions & 1 deletion src/gitHubIssueFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,29 @@ export interface GitHubIssue {
createdAt: string;
repository: GitHubRepository;
url: string;
updatedAt: string;
labels: { edges: GitHubLabelEdge[] };
}

interface GitHubRepository {
nameWithOwner: string;
}

export interface GitHubLabelEdge {
node: {
name: string;
};
}

interface Variables extends RequestParameters {
queryString: string;
pageSize: number;
maxLabelsToRetrieve: number;
after?: string;
}

const queryTemplate = `
query findByLabel($queryString:String!, $pageSize:Int, $after:String) {
query findByLabel($queryString:String!, $pageSize:Int, $maxLabelsToRetrieve:Int, $after:String) {
search(
type: ISSUE,
query: $queryString
Expand All @@ -68,6 +77,14 @@ query findByLabel($queryString:String!, $pageSize:Int, $after:String) {
nameWithOwner
}
url
updatedAt
labels(first: $maxLabelsToRetrieve) {
edges{
node{
name
}
}
}
}
}
}
Expand Down Expand Up @@ -98,6 +115,7 @@ export class GitHubIssueFetcher {
repositoryIdentifiers: string[]
): Promise<GitHubIssue[]> {
const pageSize = 100;
const maxLabelsToRetrieve = 100;
const numberOfReposPerCall = this.config.numberOfReposPerCall;
const reposForEachCall = this.splitArray(repositoryIdentifiers, numberOfReposPerCall);
const daysAgoCreated = this.config.daysAgoCreated;
Expand All @@ -109,6 +127,7 @@ export class GitHubIssueFetcher {
const variables: Variables = {
queryString: `label:"${label}" state:open ${listOfRepos} created:>${dateTimeStringForQuery}`,
pageSize,
maxLabelsToRetrieve,
};
const queryId = `${label}: ${chunk[0]}`;
const issue = await this.fetchAllPages(token, queryTemplate, variables, queryId);
Expand Down
14 changes: 13 additions & 1 deletion src/issueFinder.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { GitHubIssueFetcher, GitHubIssue } from './gitHubIssueFetcher';
import { GitHubIssueFetcher, GitHubIssue, GitHubLabelEdge } from './gitHubIssueFetcher';
import { Config } from './config';

export interface Issue {
title: string;
createdAt: string;
repositoryNameWithOwner: string;
url: string;
updatedAt: string;
labels: string[];
}

export class IssueFinder {
Expand Down Expand Up @@ -56,11 +58,21 @@ export class IssueFinder {
createdAt: node.createdAt,
repositoryNameWithOwner: node.repository.nameWithOwner,
url: node.url,
updatedAt: node.updatedAt,
labels: this.convertFromGitHubLabels(node.labels.edges),
};

return issue;
}

private convertFromGitHubLabels(edges: GitHubLabelEdge[]) {
const labels = edges.map((edge) => {
return edge.node.name;
});

return labels;
}

private omitDuplicates(issues: Issue[]): Issue[] {
const map = new Map<string, Issue>();
issues.forEach((issue) => {
Expand Down