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

Version 1.2.2 #461

Merged
merged 26 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8368b32
Drop down selector for Connect project instead of text field
jmgasper May 18, 2022
43ad8ea
Deploy for testing
jmgasper May 18, 2022
638b3e3
Updates for timeout
jmgasper May 18, 2022
0ad0c52
Further timeout test
jmgasper May 19, 2022
8d73ae2
Let’s try this
jmgasper May 19, 2022
7077279
Use ui-select (https://angular-ui.github.io/ui-select/) as dropdown s…
gets0ul May 19, 2022
eb360cf
Merge pull request #446 from gets0ul/issue-445
jmgasper May 19, 2022
cef4344
Archived projects still using copilot handle
jmgasper May 20, 2022
446b2c3
https://github.com/topcoder-platform/topcoder-x-ui/issues/448
52cs May 25, 2022
e82f6c6
Merge pull request #449 from 52cs/issue-448
jmgasper May 25, 2022
131b236
Refresh owner user/copilot Gitlab access token automatically when needed
gets0ul May 25, 2022
54055a2
Merge pull request #450 from gets0ul/issue_447
jmgasper May 25, 2022
e29301e
small fix on PR #449 for issue #448
52cs May 27, 2022
595d71c
Merge pull request #451 from 52cs/issue-448-fix
jmgasper May 30, 2022
c4e694f
Changes to Connect ID dropdown:
gets0ul May 31, 2022
8b4bf6b
Merge pull request #454 from gets0ul/issue_452
jmgasper May 31, 2022
9d11673
https://github.com/topcoder-platform/topcoder-x-ui/issues/453
52cs Jun 2, 2022
5e2a247
Merge pull request #455 from 52cs/issue-453
jmgasper Jun 2, 2022
03f10ce
fix lint of PR#455 for Issue453
52cs Jun 2, 2022
855879d
Merge pull request #456 from 52cs/fix-lint-455
jmgasper Jun 2, 2022
2d04d6a
https://github.com/topcoder-platform/topcoder-x-ui/issues/453
52cs Jun 2, 2022
5c2afde
Merge pull request #457 from 52cs/fix-issue-453
jmgasper Jun 2, 2022
c334ca3
fix-empty-tags
52cs Jun 3, 2022
aec774d
Merge pull request #458 from 52cs/fix-empty-tags/Issue#453
jmgasper Jun 3, 2022
9935ebb
https://github.com/topcoder-platform/topcoder-x-ui/issues/459
52cs Jun 14, 2022
c92f485
Merge pull request #460 from 52cs/issue-459
jmgasper Jun 14, 2022
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
45 changes: 42 additions & 3 deletions src/common/db-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,43 @@ async function queryOneIssue(model, repositoryId, number, provider) {
});
}

/**
* Get Issue's id and challengeUUID by repoUrl
* @param {String} repoUrl The repo url
* @returns {Promise<Object>}
*/
async function queryIssueIdChallengeUUIDByRepoUrl(repoUrl) {
return await new Promise((resolve, reject) => {
models.Issue.scan('repoUrl').eq(repoUrl)
.attributes(['id', 'challengeUUID'])
.exec((err, result) => {
if (err) {
return reject(err);
}
return resolve(result);
});
});
}


/**
* Get CopilotPayment's id by challengeUUID
* @param {String} challengeUUID The challengeUUID
* @returns {Promise<String>}
*/
async function queryPaymentIdByChallengeUUID(challengeUUID) {
return await new Promise((resolve, reject) => {
models.CopilotPayment.scan('challengeUUID').eq(challengeUUID)
.attributes(['id'])
.exec((err, result) => {
if (err) {
return reject(err);
}
return resolve(result.id);
});
});
}

/**
* Get single data by query parameters
* @param {Object} model The dynamoose model to query
Expand Down Expand Up @@ -257,7 +294,7 @@ async function queryOneUserMappingByTCUsername(model, tcusername) {
async function queryOneActiveProject(model, repoUrl) {
return await new Promise((resolve, reject) => {
queryOneActiveRepository(models.Repository, repoUrl).then((repo) => {
if (!repo) resolve(null);
if (!repo || repo.length === 0) resolve(null);
else model.queryOne('id').eq(repo.projectId).consistent()
.exec((err, result) => {
if (err) {
Expand Down Expand Up @@ -509,8 +546,8 @@ async function queryOneActiveRepository(model, url) {
return await new Promise((resolve, reject) => {
model.queryOne({
url,
archived: 'false'
})
.filter('archived').eq('false')
.all()
.exec((err, result) => {
if (err) {
Expand All @@ -531,8 +568,8 @@ async function queryActiveRepositoriesExcludeByProjectId(url, projectId) {
return await new Promise((resolve, reject) => {
models.Repository.query({
url,
archived: 'false'
})
.filter('archived').eq('false')
.filter('projectId')
.not().eq(projectId)
.all()
Expand Down Expand Up @@ -609,6 +646,8 @@ async function populateRepoUrls(projectId) {
}

module.exports = {
queryIssueIdChallengeUUIDByRepoUrl,
queryPaymentIdByChallengeUUID,
getById,
getByKey,
scan,
Expand Down
4 changes: 2 additions & 2 deletions src/services/CopilotPaymentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async function _ensureEditPermissionAndGetInfo(paymentId, topcoderUser) {
if (dbPayment.closed === true) {
throw new Error('Closed payment can not be updated');
}
if (dbProject.archived) {
if (dbProject.archived === 'true') {
throw new errors.ForbiddenError('You can\'t edit this payment in an archived project');
}
return dbPayment;
Expand Down Expand Up @@ -206,7 +206,7 @@ async function create(topcoderUser, payment) {
if (dbProject.copilot !== topcoderUser.handle && dbProject.owner !== topcoderUser.handle) {
throw new errors.ForbiddenError('You do not have permission to edit this payment');
}
if (dbProject.archived) {
if (dbProject.archived === 'true') {
throw new errors.ForbiddenError('You can\'t edit this payment in an archived project');
}
payment.username = dbProject.copilot;
Expand Down
2 changes: 1 addition & 1 deletion src/services/IssueService.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async function _ensureEditPermissionAndGetInfo(projectId, currentUser) {
) {
throw new errors.ForbiddenError('You don\'t have access on this project');
}
if (dbProject.archived) {
if (dbProject.archived === 'true') {
throw new errors.ForbiddenError('You can\'t access on this archived project');
}
return dbProject;
Expand Down
52 changes: 20 additions & 32 deletions src/services/ProjectService.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async function _ensureEditPermissionAndGetInfo(projectId, currentUser) {
) {
throw new errors.ForbiddenError('You don\'t have access on this project');
}
if (dbProject.archived) {
if (dbProject.archived === 'true') {
throw new errors.ForbiddenError('You can\'t access on this archived project');
}
return dbProject;
Expand Down Expand Up @@ -140,33 +140,21 @@ async function _createOrMigrateRepository(repoUrl, project, currentUser) {
or a time-sequence cornercase encountered here`);
}
try {
let oldIssues = await models.Issue.query({repoUrl: oldRepo.url});
let oldCopilotPaymentPromise = oldIssues.filter(issue => issue.challengeUUID)
.map(issue => models.CopilotPayment.query({challengeUUID: issue.challengeUUID})
.then(payments => {
if (!payments || payments.length === 0) {
/* eslint-disable-next-line no-console */
console.log(`No CopilotPayment correspond to Issue with challengeUUID ${issue.challengeUUID}.
The corresponding CopilotPayment may have been removed.
Or, there is bug in old version.`);
return null;
}
if (payments.length > 1) {
throw new Error(`Duplicate CopilotPayment correspond to one Issue with challengeUUID ${issue.challengeUUID}.
There must be bug in old version`);
}
return payments[0];
}));
let oldCopilotPayment = await Promise.all(oldCopilotPaymentPromise).filter(payment => payment);

await models.Repository.update({id: oldRepo.id}, {projectId: project.id, archived: false});
await oldIssues.forEach(issue => models.Issue.update({id: issue.id}, {projectId: project.id}));
await oldCopilotPayment.forEach(
payment => models.CopilotPayment.update({id: payment.id}, {project: project.id})
const oldIssues = await dbHelper.queryIssueIdChallengeUUIDByRepoUrl(repoUrl);
const issueIds = oldIssues.map(issue => issue.id);
const challengeUUIDs = oldIssues.map(issue => issue.challengeUUID).filter(challengeUUID => challengeUUID);
const paymentIds = await Promise.all(
challengeUUIDs.map(challengeUUID => dbHelper.queryPaymentIdByChallengeUUID(challengeUUID))
);

await dbHelper.update(models.Repository, oldRepo.id, {projectId: project.id, archived: false});
await Promise.all(issueIds.map(issueId => dbHelper.update(models.Issue, issueId, {projectId: project.id})));
await Promise.all(
paymentIds.map(paymentId => dbHelper.update(models.CopilotPayment, paymentId, {project: project.id}))
);
}
catch (err) {
throw new Error(`Update ProjectId for Repository, Issue, CopilotPayment failed. Repo ${repoUrl}. Internal Error: ${err.message}`);
throw new Error(`Update ProjectId for Repository, Issue, CopilotPayment failed. Repo ${repoUrl}. Internal Error: ${err}`);
}
} else {
try {
Expand All @@ -181,7 +169,7 @@ async function _createOrMigrateRepository(repoUrl, project, currentUser) {
await addWikiRules({projectId: project.id}, currentUser, repoUrl);
}
catch (err) {
throw new Error(`Project created. Adding the webhook, issue labels, and wiki rules failed. Repo ${repoUrl}. Internal Error: ${err.message}`);
throw new Error(`Project created. Adding the webhook, issue labels, and wiki rules failed. Repo ${repoUrl}. Internal Error: ${err}`);
}
}
}
Expand Down Expand Up @@ -213,6 +201,8 @@ async function create(project, currentUser) {
project.copilot = project.copilot ? project.copilot.toLowerCase() : null;
project.id = helper.generateIdentifier();

const createdProject = await dbHelper.create(models.Project, project);

// TODO: The following db operation should/could be moved into one transaction
for (const repoUrl of repoUrls) { // eslint-disable-line no-restricted-syntax
try {
Expand All @@ -222,7 +212,6 @@ async function create(project, currentUser) {
throw new Error(`Create or migrate repository failed. Repo ${repoUrl}. Internal Error: ${err.message}`);
}
}
const createdProject = await dbHelper.create(models.Project, project);

return createdProject;
}
Expand Down Expand Up @@ -267,12 +256,12 @@ async function update(project, currentUser) {
});

// TODO: move the following logic into one dynamoose transaction
const repoUrl2Repo = await dbHelper.queryRepositoriesByProjectId(dbProject.id)
.map(repo => { return {[repo.url]: repo}; });
const repos = await dbHelper.queryRepositoriesByProjectId(dbProject.id);

for (const repoUrl of repoUrls) { // eslint-disable-line no-restricted-syntax
if (repoUrl in repoUrl2Repo) {
await models.Repository.update({id: repoUrl2Repo[repoUrl].id}, {archived: project.archived});
if (repos.find(repo => repo.url === repoUrl)) {
const repoId = repos.find(repo => repo.url === repoUrl).id
await dbHelper.update(models.Repository, repoId, {archived: project.archived});
} else {
try {
await _createOrMigrateRepository(repoUrl, project, currentUser);
Expand Down Expand Up @@ -319,7 +308,6 @@ async function getAll(query, currentUser) {
query.lastKey = parseInt(query.lastKey, 10);
}
const slicedProjects = _.slice(projects, query.lastKey, query.lastKey + query.perPage);
// console.log(projects);
for (const project of slicedProjects) { // eslint-disable-line
project.repoUrls = await dbHelper.populateRepoUrls(project.id);
}
Expand Down