Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Version 1.2 #427

Merged
merged 3 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Challenge for August release
  • Loading branch information
jmgasper committed Aug 12, 2021
commit 75aba5433e8642fe4ccf36061c1fb7a6ac691abe
2 changes: 1 addition & 1 deletion TopcoderXDeploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ You can do this by clicking your logged in username in the upper right of the To

Once you have registered your account, go into `Project Management` and add a new project for either a Gitlab or Github project you have access to. Gitlab is likely easier for testing - you can create a free test project under your own account.

Use Topcoder Connect ID `16665` since this has a valid billing account in the dev environment.
Use Topcoder Connect ID `17249` since this has a valid billing account in the dev environment.

Once it's been added, click `Manage` for the project in the list on `Project Management` and click `Add Webhooks`. Once the webhook has been added, you should be able to see it in the Gitlab project under `Settings` --> `Integrations` --> `Webhooks`

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"create-tables": "CREATE_DB=true node scripts/create-update-tables.js",
"migrate-user-mapping": "node scripts/migrate-user-mapping.js",
"add-organisation": "node scripts/add-organisation.js",
"log-repository-collisions": "node scripts/log-repository-collisions.js"
"log-repository-collisions": "node scripts/log-repository-collisions.js",
"migrate-repo-url": "node scripts/migrate-repo-url.js"
},
"dependencies": {
"angular": "~1.8.0",
Expand Down
28 changes: 15 additions & 13 deletions scripts/log-repository-collisions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ async function main() {
archived: 'false'
}).consistent().limit(BATCH_SIZE).startAt(previousKey).exec()
for (const project of projects) {
// If url was already found colliding go to a next iteration
if (collidingUrls.includes(project.repoUrl)) continue;
const collisions = await models.Project.scan({
repoUrl: project.repoUrl,
archived: 'false'
}).exec()
// If scan found only this project go to a next interation
if (collisions.length < 2) continue;
logger.info(`Repository ${project.repoUrl} has ${collisions.length} collisions`);
_.forEach(collisions, collision => {
logger.info(`--- ID: ${collision.id}`)
})
collidingUrls.push(project.repoUrl)
for (const repoUrl of project.repoUrls) {
// If url was already found colliding go to a next iteration
if (collidingUrls.includes(repoUrl)) continue;
const collisions = await models.Project.scan({
repoUrl: { contains: project.repoUrl },
archived: 'false'
}).exec()
// If scan found only this project go to a next interation
if (collisions.length < 2) continue;
logger.info(`Repository ${repoUrl} has ${collisions.length} collisions`);
_.forEach(collisions, collision => {
logger.info(`--- ID: ${collision.id}`)
})
collidingUrls.push(repoUrl)
}
}
previousKey = projects.lastKey
previousSize = projects.scannedCount
Expand Down
29 changes: 29 additions & 0 deletions scripts/migrate-repo-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const AWS = require('aws-sdk');
const helper = require('../src/common/helper');
const dbHelper = require('../src/common/db-helper');
const Project = require('../src/models').Project;

if (process.env.IS_LOCAL=="true") {
AWS.config.update({
endpoint: 'http://localhost:8000'
});
}
var documentClient = new AWS.DynamoDB.DocumentClient();

(async () => {
console.log('Migrating...');
const params = {
TableName: 'Topcoder_X.Project'
};

let items;
do {
items = await documentClient.scan(params).promise();
items.Items.forEach(async (item) => {
console.log(item);
item.repoUrls = [item.repoUrl];
await dbHelper.update(Project, item.id, item);
});
params.ExclusiveStartKey = items.LastEvaluatedKey;
} while(typeof items.LastEvaluatedKey !== 'undefined');
})();
20 changes: 10 additions & 10 deletions src/common/db-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async function scan(model, scanParams) {
model.scan(scanParams).exec((err, result) => {
if (err) {
logger.error(`DynamoDB scan error ${err}`);
reject(err);
return reject(err);
}

return resolve(result.count === 0 ? [] : result);
Expand Down Expand Up @@ -171,8 +171,8 @@ async function queryOneUserMappingByTCUsername(model, tcusername) {
*/
async function queryOneActiveProject(model, repoUrl) {
return await new Promise((resolve, reject) => {
model.query('repoUrl').eq(repoUrl)
.where('archived')
model.scan('repoUrls').contains(repoUrl)
.filter('archived')
.eq('false')
.all()
.exec((err, result) => {
Expand Down Expand Up @@ -202,7 +202,7 @@ async function queryOneActiveCopilotPayment(model, project, username) {
.all()
.exec((err, result) => {
if (err || !result) {
logger.debug(`queryOneActiveProject. Error. ${err}`);
logger.debug(`queryOneActiveCopilotPayment. Error. ${err}`);
return reject(err);
}
return resolve(result.count === 0 ? null : result[0]);
Expand All @@ -225,7 +225,7 @@ async function queryOneUserGroupMapping(model, groupId, gitlabUserId) {
.all()
.exec((err, result) => {
if (err || !result) {
logger.debug(`queryOneActiveProject. Error. ${err}`);
logger.debug(`queryOneUserGroupMapping. Error. ${err}`);
return reject(err);
}
return resolve(result.count === 0 ? null : result[0]);
Expand All @@ -251,7 +251,7 @@ async function queryOneUserTeamMapping(model, teamId, githubUserName, githubOrgI
.all()
.exec((err, result) => {
if (err || !result) {
logger.debug(`queryOneActiveProject. Error. ${err}`);
logger.debug(`queryOneUserTeamMapping. Error. ${err}`);
return reject(err);
}
return resolve(result.count === 0 ? null : result[0]);
Expand All @@ -268,15 +268,15 @@ async function queryOneUserTeamMapping(model, teamId, githubUserName, githubOrgI
*/
async function queryOneActiveProjectWithFilter(model, repoUrl, projectIdToFilter) {
return await new Promise((resolve, reject) => {
model.query('repoUrl').eq(repoUrl)
.where('archived')
model.scan('repoUrls').contains(repoUrl)
.filter('archived')
.eq('false')
.filter('id')
.not().eq(projectIdToFilter)
.all()
.exec((err, result) => {
if (err || !result) {
logger.debug(`queryOneActiveProject. Error. ${err}`);
logger.debug(`queryOneActiveProjectWithFilter. Error. ${err}`);
return reject(err);
}
return resolve(result.count === 0 ? null : result[0]);
Expand All @@ -296,7 +296,7 @@ async function create(Model, data) {
dbItem.save((err) => {
if (err) {
logger.error(`DynamoDB create error ${err}`);
reject(err);
return reject(err);
}

return resolve(dbItem);
Expand Down
51 changes: 51 additions & 0 deletions src/controllers/GithubPATsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2018 TopCoder, Inc. All rights reserved.
*/

/**
* This controller exposes Github PATs endpoints.
*
* @author kevinkid
* @version 1.0
*/
const helper = require('../common/helper');
const GithubPATsService = require('../services/GithubPATsService');

/**
* searches the pat according to criteria
* @param {Object} req the request
* @param {Object} res the response
* @returns {Object} the result
*/
async function search(req) {
return await GithubPATsService.search(req.query);
}

/**
* create pat
* @param {Object} req the request
* @param {Object} res the response
* @returns {Object} the result
*/
async function create(req) {
return await GithubPATsService.create(req.body.pat);
}

/**
* remove pat item
* @param {Object} req the request
* @param {Object} res the response
* @returns {Object} the result
*/
async function remove(req) {
return await GithubPATsService.remove(req.params.id);
}


module.exports = {
search,
create,
remove,
};

helper.buildController(module.exports);
40 changes: 37 additions & 3 deletions src/controllers/ProjectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
const helper = require('../common/helper');
const ProjectService = require('../services/ProjectService');
const models = require('../models');

/**
* create project
Expand Down Expand Up @@ -47,7 +48,18 @@ async function getAll(req) {
* @returns {Object} the result
*/
async function createLabel(req) {
return await ProjectService.createLabel(req.body, req.currentUser);
const dbProject = await helper.ensureExists(models.Project, req.body.projectId, 'Project');
for (const repoUrl of dbProject.repoUrls) { // eslint-disable-line no-restricted-syntax
try {
await ProjectService.createLabel(req.body, req.currentUser, repoUrl);
}
catch (err) {
throw new Error(`Adding the labels failed. Repo ${repoUrl}`);
}
}
return {
success: false
};
}

/**
Expand All @@ -57,7 +69,18 @@ async function createLabel(req) {
* @returns {Object} the result
*/
async function createHook(req) {
return await ProjectService.createHook(req.body, req.currentUser);
const dbProject = await helper.ensureExists(models.Project, req.body.projectId, 'Project');
for (const repoUrl of dbProject.repoUrls) { // eslint-disable-line no-restricted-syntax
try {
await ProjectService.createHook(req.body, req.currentUser, repoUrl);
}
catch (err) {
throw new Error(`Adding the webhook failed. Repo ${repoUrl}`);
}
}
return {
success: false
};
}

/**
Expand All @@ -67,7 +90,18 @@ async function createHook(req) {
* @returns {Object} the result
*/
async function addWikiRules(req) {
return await ProjectService.addWikiRules(req.body, req.currentUser);
const dbProject = await helper.ensureExists(models.Project, req.body.projectId, 'Project');
for (const repoUrl of dbProject.repoUrls) { // eslint-disable-line no-restricted-syntax
try {
await ProjectService.addWikiRules(req.body, req.currentUser, repoUrl);
}
catch (err) {
throw new Error(`Adding the wiki rules failed. Repo ${repoUrl}`);
}
}
return {
success: false
};
}

/**
Expand Down
44 changes: 44 additions & 0 deletions src/controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,54 @@ async function getUserToken(req) {
return await UserService.getUserToken(req.query.username, req.query.tokenType);
}

/**
* searches user mappings according to criteria
* @param {Object} req the request
* @param {Object} res the response
* @returns {Object} the result
*/
async function search(req) {
return await UserService.search(req.query);
}

/**
* create user mapping
* @param {Object} req the request
* @param {Object} res the response
* @returns {Object} the result
*/
async function create(req) {
return await UserService.create(req.body.userMapping);
}

/**
* update user mapping
* @param {Object} req the request
* @param {Object} res the response
* @returns {Object} the result
*/
async function update(req) {
return await UserService.update(req.body.userMapping);
}

/**
* remove user mapping
* @param {Object} req the request
* @param {Object} res the response
* @returns {Object} the result
*/
async function remove(req) {
return await UserService.remove(req.params.username);
}

module.exports = {
getUserSetting,
revokeUserSetting,
getUserToken,
search,
create,
remove,
update,
};

helper.buildController(module.exports);
32 changes: 32 additions & 0 deletions src/front/src/app/add-github-pat/add-github-pat-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

angular.module('topcoderX')
.controller('AddGithubPATController', ['$scope', '$state', 'GithubPATsService', 'Alert',
function ($scope, $state, GithubPATsService, Alert) {
$scope.pat = {
name: '',
owner: '',
personalAccessToken: ''
};

// handle error output
function _handleError(error, defaultMsg) {
const errMsg = error.data ? error.data.message : defaultMsg;
Alert.error(errMsg, $scope);
}

// create/update pat item
$scope.save = function () {
if (!$scope.editing) {
GithubPATsService.create($scope.pat).then(function (response) {
if (response.data.exist) {
Alert.error('Organisation is already exist with a PAT. Please delete first.', $scope);
}
else $state.go('app.githubPATs');
}).catch(function (error) {
_handleError(error, 'An error occurred while creating PAT.');
});
}
};
}
]);
Loading