Skip to content

Commit 3fa6755

Browse files
feat: add project releases view resolver (#563)
* feat: add project releases view resolver * fix: lint * fix: remove minTs * run ci * run ci * Bump version up to 1.2.9 * run ci --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent fd26eca commit 3fa6755

4 files changed

Lines changed: 113 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ To execute the request, enter it in the input field on the left and click on the
2525
On the right side you will see the result of the query.
2626

2727
## GraphQL Voyager
28-
You can view API Schema visualization in `/voyager` page in your browser. To see current production schema go to [here](https://api.beta.hawk.so/voyager)
28+
You can view API Schema visualization in `/voyager` page in your browser.
29+
To see current production schema go to [here](https://api.beta.hawk.so/voyager)
2930

3031
## Migrations
3132

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hawk.api",
3-
"version": "1.2.8",
3+
"version": "1.2.9",
44
"main": "index.ts",
55
"license": "BUSL-1.1",
66
"scripts": {

src/resolvers/project.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,5 +397,80 @@ module.exports = {
397397

398398
return factory.findChartData(days, timezoneOffset);
399399
},
400+
401+
/**
402+
* Returns list of not archived releases with number of events that were introduced in this release
403+
* We count events as new, cause payload.release only contain the same release name if the event is original
404+
*
405+
* @param {ProjectDBScheme} project - result of parent resolver
406+
* @returns {Promise<Array<{release: string, timestamp: number, newEventsCount: number, commitsCount: number, filesCount: number}>>}
407+
*/
408+
async releases(project) {
409+
const releasesCollection = mongo.databases.events.collection('releases');
410+
411+
const pipeline = [
412+
{ $match: { projectId: project._id.toString() } },
413+
{
414+
$project: {
415+
release: {
416+
$convert: {
417+
input: '$release',
418+
to: 'string',
419+
onError: '',
420+
onNull: '',
421+
},
422+
},
423+
commitsCount: { $size: { $ifNull: ['$commits', [] ] } },
424+
filesCount: { $size: { $ifNull: ['$files', [] ] } },
425+
_releaseIdSec: { $floor: { $divide: [ { $toLong: { $toDate: '$_id' } }, 1000] } },
426+
},
427+
},
428+
{
429+
$lookup: {
430+
from: 'events:' + project._id,
431+
let: { rel: '$release' },
432+
pipeline: [
433+
{
434+
$match: {
435+
$expr: {
436+
$eq: [ {
437+
$convert: {
438+
input: '$payload.release',
439+
to: 'string',
440+
onError: '',
441+
onNull: '',
442+
},
443+
}, '$$rel'],
444+
},
445+
},
446+
},
447+
{
448+
$group: {
449+
_id: null,
450+
count: { $sum: 1 },
451+
},
452+
},
453+
],
454+
as: 'eventAgg',
455+
},
456+
},
457+
{
458+
$project: {
459+
_id: 0,
460+
release: 1,
461+
commitsCount: 1,
462+
filesCount: 1,
463+
newEventsCount: { $ifNull: [ { $arrayElemAt: ['$eventAgg.count', 0] }, 0] },
464+
timestamp: '$_releaseIdSec',
465+
},
466+
},
467+
{ $sort: { _id: -1 } },
468+
];
469+
470+
const cursor = releasesCollection.aggregate(pipeline);
471+
const result = await cursor.toArray();
472+
473+
return result;
474+
},
400475
},
401476
};

src/typeDefs/project.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,36 @@ input EventsFiltersInput {
9696
ignored: Boolean
9797
}
9898
99+
"""
100+
Aggregated release info for project events
101+
"""
102+
type ProjectRelease {
103+
"""
104+
Release identifier
105+
"""
106+
release: String!
107+
108+
"""
109+
First occurrence timestamp
110+
"""
111+
timestamp: Float!
112+
113+
"""
114+
Number of new events introduced in this release
115+
"""
116+
newEventsCount: Int!
117+
118+
"""
119+
Number of commits in this release
120+
"""
121+
commitsCount: Int!
122+
123+
"""
124+
Number of files in this release
125+
"""
126+
filesCount: Int!
127+
}
128+
99129
"""
100130
Respose object with updated project and his id
101131
"""
@@ -253,6 +283,11 @@ type Project {
253283
Event grouping patterns
254284
"""
255285
eventGroupingPatterns: [ProjectEventGroupingPattern]
286+
287+
"""
288+
List of releases with unique events count, commits count and files count
289+
"""
290+
releases: [ProjectRelease!]!
256291
}
257292
258293
extend type Query {

0 commit comments

Comments
 (0)