Skip to content

Commit 2f5d7b5

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 95b9f56 commit 2f5d7b5

File tree

4 files changed

+113
-2
lines changed

4 files changed

+113
-2
lines changed

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
@@ -470,5 +470,80 @@ module.exports = {
470470

471471
return factory.findChartData(days, timezoneOffset);
472472
},
473+
474+
/**
475+
* Returns list of not archived releases with number of events that were introduced in this release
476+
* We count events as new, cause payload.release only contain the same release name if the event is original
477+
*
478+
* @param {ProjectDBScheme} project - result of parent resolver
479+
* @returns {Promise<Array<{release: string, timestamp: number, newEventsCount: number, commitsCount: number, filesCount: number}>>}
480+
*/
481+
async releases(project) {
482+
const releasesCollection = mongo.databases.events.collection('releases');
483+
484+
const pipeline = [
485+
{ $match: { projectId: project._id.toString() } },
486+
{
487+
$project: {
488+
release: {
489+
$convert: {
490+
input: '$release',
491+
to: 'string',
492+
onError: '',
493+
onNull: '',
494+
},
495+
},
496+
commitsCount: { $size: { $ifNull: ['$commits', [] ] } },
497+
filesCount: { $size: { $ifNull: ['$files', [] ] } },
498+
_releaseIdSec: { $floor: { $divide: [ { $toLong: { $toDate: '$_id' } }, 1000] } },
499+
},
500+
},
501+
{
502+
$lookup: {
503+
from: 'events:' + project._id,
504+
let: { rel: '$release' },
505+
pipeline: [
506+
{
507+
$match: {
508+
$expr: {
509+
$eq: [ {
510+
$convert: {
511+
input: '$payload.release',
512+
to: 'string',
513+
onError: '',
514+
onNull: '',
515+
},
516+
}, '$$rel'],
517+
},
518+
},
519+
},
520+
{
521+
$group: {
522+
_id: null,
523+
count: { $sum: 1 },
524+
},
525+
},
526+
],
527+
as: 'eventAgg',
528+
},
529+
},
530+
{
531+
$project: {
532+
_id: 0,
533+
release: 1,
534+
commitsCount: 1,
535+
filesCount: 1,
536+
newEventsCount: { $ifNull: [ { $arrayElemAt: ['$eventAgg.count', 0] }, 0] },
537+
timestamp: '$_releaseIdSec',
538+
},
539+
},
540+
{ $sort: { _id: -1 } },
541+
];
542+
543+
const cursor = releasesCollection.aggregate(pipeline);
544+
const result = await cursor.toArray();
545+
546+
return result;
547+
},
473548
},
474549
};

src/typeDefs/project.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,36 @@ input EventsFiltersInput {
125125
ignored: Boolean
126126
}
127127
128+
"""
129+
Aggregated release info for project events
130+
"""
131+
type ProjectRelease {
132+
"""
133+
Release identifier
134+
"""
135+
release: String!
136+
137+
"""
138+
First occurrence timestamp
139+
"""
140+
timestamp: Float!
141+
142+
"""
143+
Number of new events introduced in this release
144+
"""
145+
newEventsCount: Int!
146+
147+
"""
148+
Number of commits in this release
149+
"""
150+
commitsCount: Int!
151+
152+
"""
153+
Number of files in this release
154+
"""
155+
filesCount: Int!
156+
}
157+
128158
"""
129159
Respose object with updated project and his id
130160
"""
@@ -287,6 +317,11 @@ type Project {
287317
Rate limits configuration
288318
"""
289319
rateLimitSettings: RateLimitSettings
320+
321+
"""
322+
List of releases with unique events count, commits count and files count
323+
"""
324+
releases: [ProjectRelease!]!
290325
}
291326
292327
extend type Query {

0 commit comments

Comments
 (0)