Skip to content

Commit

Permalink
feat: save commits in database
Browse files Browse the repository at this point in the history
  • Loading branch information
akawula committed Feb 5, 2024
1 parent 1444699 commit abc4445
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/helpers/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export interface PullRequest {
}

interface Commit {
message: string
commit: {
message: string
},
id: string
}

interface PullRequestsResponse {
Expand Down Expand Up @@ -149,6 +152,7 @@ const PULL_REQUESTS_QUERY = `
commit {
message
}
id
}
totalCount
}
Expand Down Expand Up @@ -261,7 +265,7 @@ export async function fetchOrganizationRepositories(token: string, organization:


const findJiraKeys = (pr: PullRequest) => {
const toBeSearched: string[] = [pr.headRefName, pr.title, ...pr.commits.nodes.map((x: Commit) => x.message)];
const toBeSearched: string[] = [pr.headRefName, pr.title, ...pr.commits.nodes.map((x: Commit) => x.commit.message)];
let keys: string[] = [];
while (toBeSearched.length) {
const value: string = toBeSearched.shift() || '';
Expand Down Expand Up @@ -320,6 +324,10 @@ export default async function fetchAuthorPullRequests(token: string, author: str
try {
await db.execute(`INSERT OR IGNORE INTO prs (id, title, state, url, mergedAt, createdAt, additions, deletions, branchName, authorLogin, authorAvatarUrl, repository, reviewRequestedEventAt, JIRA, timeToMerge, timeToMergeRaw) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)`,
[x.id, x.title, x.state, x.url, x.mergedAt, x.createdAt, x.additions, x.deletions, x.headRefName, x.author.login, x.author.avatarUrl, x.repository.name, x.timelineItems.nodes.length && x.timelineItems.nodes[0].createdAt ? x.timelineItems.nodes[0].createdAt : x.createdAt, x.JIRA, x.timeToMerge, x.timeToMergeRaw]);
x.commits.nodes.map(async (commit: Commit) => {
console.log(commit);
await db.execute(`INSERT OR IGNORE INTO commits (id, message, prID) VALUES ($1, $2, $3)`, [commit.id, commit.commit.message, x.id]);
});
}
catch (error) {
console.log(error);
Expand Down

0 comments on commit abc4445

Please sign in to comment.