Skip to content

Commit cc0b480

Browse files
committed
feat: add project releases view resolver
1 parent fd26eca commit cc0b480

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

src/resolvers/project.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,5 +397,58 @@ 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 releasesCol = mongo.databases.events.collection('releases');
410+
411+
const pipeline = [
412+
{ $match: { projectId: project._id.toString() } },
413+
{
414+
$project: {
415+
release: { $convert: { input: '$release', to: 'string', onError: '', onNull: '' } },
416+
commitsCount: { $size: { $ifNull: ['$commits', []] } },
417+
filesCount: { $size: { $ifNull: ['$files', []] } },
418+
_releaseIdSec: { $floor: { $divide: [ { $toLong: { $toDate: '$_id' } }, 1000 ] } },
419+
},
420+
},
421+
{ $match: { release: { $ne: '' } } },
422+
{
423+
$lookup: {
424+
from: 'events:' + project._id,
425+
let: { rel: '$release' },
426+
pipeline: [
427+
{ $match: { $expr: { $eq: [ { $convert: { input: '$payload.release', to: 'string', onError: '', onNull: '' } }, '$$rel' ] } } },
428+
{ $group: { _id: null, minTs: { $min: '$timestamp' }, count: { $sum: 1 } } },
429+
],
430+
as: 'eventAgg',
431+
},
432+
},
433+
{
434+
$project: {
435+
_id: 0,
436+
release: 1,
437+
commitsCount: 1,
438+
filesCount: 1,
439+
newEventsCount: { $ifNull: [ { $arrayElemAt: ['$eventAgg.count', 0] }, 0 ] },
440+
timestamp: {
441+
$ifNull: [ { $arrayElemAt: ['$eventAgg.minTs', 0] }, '$_releaseIdSec' ],
442+
},
443+
},
444+
},
445+
{ $sort: { timestamp: -1 } },
446+
];
447+
448+
const cursor = releasesCol.aggregate(pipeline);
449+
const result = await cursor.toArray();
450+
451+
return result;
452+
},
400453
},
401454
};

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 first mention timestamp and events count
289+
"""
290+
releases: [ProjectRelease!]!
256291
}
257292
258293
extend type Query {

0 commit comments

Comments
 (0)