Skip to content
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ To execute the request, enter it in the input field on the left and click on the
On the right side you will see the result of the query.

## GraphQL Voyager
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)
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)

## Migrations

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawk.api",
"version": "1.2.8",
"version": "1.2.9",
"main": "index.ts",
"license": "BUSL-1.1",
"scripts": {
Expand Down
75 changes: 75 additions & 0 deletions src/resolvers/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,5 +397,80 @@ module.exports = {

return factory.findChartData(days, timezoneOffset);
},

/**
* Returns list of not archived releases with number of events that were introduced in this release
* We count events as new, cause payload.release only contain the same release name if the event is original
*
* @param {ProjectDBScheme} project - result of parent resolver
* @returns {Promise<Array<{release: string, timestamp: number, newEventsCount: number, commitsCount: number, filesCount: number}>>}
*/
async releases(project) {
const releasesCollection = mongo.databases.events.collection('releases');

const pipeline = [
{ $match: { projectId: project._id.toString() } },
{
$project: {
release: {
$convert: {
input: '$release',
to: 'string',
onError: '',
onNull: '',
},
},
commitsCount: { $size: { $ifNull: ['$commits', [] ] } },
filesCount: { $size: { $ifNull: ['$files', [] ] } },
_releaseIdSec: { $floor: { $divide: [ { $toLong: { $toDate: '$_id' } }, 1000] } },
},
},
{
$lookup: {
from: 'events:' + project._id,
let: { rel: '$release' },
pipeline: [
{
$match: {
$expr: {
$eq: [ {
$convert: {
input: '$payload.release',
to: 'string',
onError: '',
onNull: '',
},
}, '$$rel'],
},
},
},
{
$group: {
_id: null,
count: { $sum: 1 },
},
},
],
as: 'eventAgg',
},
},
{
$project: {
_id: 0,
release: 1,
commitsCount: 1,
filesCount: 1,
newEventsCount: { $ifNull: [ { $arrayElemAt: ['$eventAgg.count', 0] }, 0] },
timestamp: '$_releaseIdSec',
},
},
{ $sort: { _id: -1 } },
];

const cursor = releasesCollection.aggregate(pipeline);
const result = await cursor.toArray();

return result;
},
},
};
35 changes: 35 additions & 0 deletions src/typeDefs/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,36 @@ input EventsFiltersInput {
ignored: Boolean
}

"""
Aggregated release info for project events
"""
type ProjectRelease {
"""
Release identifier
"""
release: String!

"""
First occurrence timestamp
"""
timestamp: Float!

"""
Number of new events introduced in this release
"""
newEventsCount: Int!

"""
Number of commits in this release
"""
commitsCount: Int!

"""
Number of files in this release
"""
filesCount: Int!
}

"""
Respose object with updated project and his id
"""
Expand Down Expand Up @@ -253,6 +283,11 @@ type Project {
Event grouping patterns
"""
eventGroupingPatterns: [ProjectEventGroupingPattern]

"""
List of releases with unique events count, commits count and files count
"""
releases: [ProjectRelease!]!
}

extend type Query {
Expand Down
Loading