Skip to content

Commit

Permalink
Add webhooks (cvat-ai#4863)
Browse files Browse the repository at this point in the history
Co-authored-by: “klakhov” <kirill.lakhov@cvat.ai>
Co-authored-by: Boris <sekachev.bs@gmail.com>
Co-authored-by: kirill-sizov <kirill.sizov@intel.com>
  • Loading branch information
4 people committed Sep 28, 2022
1 parent 8b719e4 commit bae7564
Show file tree
Hide file tree
Showing 88 changed files with 8,294 additions and 380 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
'.eslintrc.js',
'lint-staged.config.js',
],
plugins: ['@typescript-eslint', 'security', 'no-unsanitized', 'eslint-plugin-header', 'import'],
plugins: ['@typescript-eslint', 'security', 'no-unsanitized', 'import'],
extends: [
'eslint:recommended', 'plugin:security/recommended', 'plugin:no-unsanitized/DOM',
'airbnb-base', 'plugin:import/errors', 'plugin:import/warnings',
Expand Down
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@
"env": {},
"console": "internalConsole"
},
{
"name": "server: RQ - webhooks",
"type": "python",
"request": "launch",
"justMyCode": false,
"stopOnEntry": false,
"python": "${command:python.interpreterPath}",
"program": "${workspaceRoot}/manage.py",
"args": [
"rqworker",
"webhooks",
"--worker-class",
"cvat.simpleworker.SimpleWorker",
],
"django": true,
"cwd": "${workspaceFolder}",
"env": {},
"console": "internalConsole"
},
{
"name": "server: git",
"type": "python",
Expand Down Expand Up @@ -285,6 +304,7 @@
"server: django",
"server: RQ - default",
"server: RQ - low",
"server: RQ - webhooks",
"server: RQ - scheduler",
"server: git",
]
Expand Down
37 changes: 36 additions & 1 deletion cvat-core/src/api-implementation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) 2019-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -17,13 +18,14 @@ const config = require('./config');
checkObjectType,
} = require('./common');

const User = require('./user');
const User = require('./user').default;
const { AnnotationFormats } = require('./annotation-formats');
const { ArgumentError } = require('./exceptions');
const { Task, Job } = require('./session');
const Project = require('./project').default;
const { CloudStorage } = require('./cloud-storage');
const Organization = require('./organization');
const Webhook = require('./webhook').default;

function implementAPI(cvat) {
cvat.plugins.list.implementation = PluginRegistry.list;
Expand Down Expand Up @@ -286,6 +288,39 @@ const config = require('./config');
config.organizationID = null;
};

cvat.webhooks.get.implementation = async (filter) => {
checkFilter(filter, {
page: isInteger,
id: isInteger,
projectId: isInteger,
filter: isString,
search: isString,
sort: isString,
});

checkExclusiveFields(filter, ['id', 'projectId'], ['page']);
const searchParams = {};
for (const key of Object.keys(filter)) {
if (['page', 'id', 'filter', 'search', 'sort'].includes(key)) {
searchParams[key] = filter[key];
}
}

if (filter.projectId) {
if (searchParams.filter) {
const parsed = JSON.parse(searchParams.filter);
searchParams.filter = JSON.stringify({ and: [parsed, { '==': [{ var: 'project_id' }, filter.projectId] }] });
} else {
searchParams.filter = JSON.stringify({ and: [{ '==': [{ var: 'project_id' }, filter.projectId] }] });
}
}

const webhooksData = await serverProxy.webhooks.get(searchParams);
const webhooks = webhooksData.map((webhookData) => new Webhook(webhookData));
webhooks.count = webhooksData.count;
return webhooks;
};

return cvat;
}

Expand Down
25 changes: 24 additions & 1 deletion cvat-core/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) 2019-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -23,14 +24,15 @@ function build() {
const { FrameData } = require('./frames');
const { CloudStorage } = require('./cloud-storage');
const Organization = require('./organization');
const Webhook = require('./webhook').default;

const enums = require('./enums');

const {
Exception, ArgumentError, DataError, ScriptingError, PluginError, ServerError,
} = require('./exceptions');

const User = require('./user');
const User = require('./user').default;
const pjson = require('../package.json');
const config = require('./config');

Expand Down Expand Up @@ -843,6 +845,26 @@ function build() {
return result;
},
},
/**
* This namespace could be used to get webhooks list from the server
* @namespace webhooks
* @memberof module:API.cvat
*/
webhooks: {
/**
* Method returns a list of organizations
* @method get
* @async
* @memberof module:API.cvat.webhooks
* @returns {module:API.cvat.classes.Webhook[]}
* @throws {module:API.cvat.exceptions.PluginError}
* @throws {module:API.cvat.exceptions.ServerError}
*/
async get(filter: any) {
const result = await PluginRegistry.apiWrapper(cvat.webhooks.get, filter);
return result;
},
},
/**
* Namespace is used for access to classes
* @namespace classes
Expand All @@ -864,6 +886,7 @@ function build() {
FrameData,
CloudStorage,
Organization,
Webhook,
},
};

Expand Down
3 changes: 2 additions & 1 deletion cvat-core/src/comment.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (C) 2020-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

const User = require('./user');
const User = require('./user').default;
const { ArgumentError } = require('./exceptions');

/**
Expand Down
26 changes: 26 additions & 0 deletions cvat-core/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,29 @@ export enum StorageLocation {
LOCAL = 'local',
CLOUD_STORAGE = 'cloud_storage',
}

/**
* Webhook source types
* @enum {string}
* @name WebhookSourceType
* @memberof module:API.cvat.enums
* @property {string} ORGANIZATION 'organization'
* @property {string} PROJECT 'project'
* @readonly
*/
export enum WebhookSourceType {
ORGANIZATION = 'organization',
PROJECT = 'project',
}

/**
* Webhook content types
* @enum {string}
* @name WebhookContentType
* @memberof module:API.cvat.enums
* @property {string} JSON 'json'
* @readonly
*/
export enum WebhookContentType {
JSON = 'application/json',
}
3 changes: 2 additions & 1 deletion cvat-core/src/issue.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright (C) 2020-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

const quickhull = require('quickhull');

const PluginRegistry = require('./plugins').default;
const Comment = require('./comment');
const User = require('./user');
const User = require('./user').default;
const { ArgumentError } = require('./exceptions');
const serverProxy = require('./server-proxy').default;

Expand Down
3 changes: 2 additions & 1 deletion cvat-core/src/organization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -8,7 +9,7 @@ const { MembershipRole } = require('./enums');
const { ArgumentError, ServerError } = require('./exceptions');
const PluginRegistry = require('./plugins').default;
const serverProxy = require('./server-proxy').default;
const User = require('./user');
const User = require('./user').default;

/**
* Class representing an organization
Expand Down
2 changes: 1 addition & 1 deletion cvat-core/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Storage } from './storage';
const PluginRegistry = require('./plugins').default;
const { ArgumentError } = require('./exceptions');
const { Label } = require('./labels');
const User = require('./user');
const User = require('./user').default;
const { FieldUpdateTrigger } = require('./common');

/**
Expand Down
Loading

0 comments on commit bae7564

Please sign in to comment.