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

Commit 5af4454

Browse files
committed
August 2019 release challenge
1 parent 8baf5eb commit 5af4454

15 files changed

+308
-31
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ npm run lint
4747
- post /projects/hook - create webhooks in the project repository
4848
- GET /users/settings - gets the current user's setup
4949
- GET /users/accessToken - gets the user's access token
50-
50+
51+
- POST /issues - create an issue to Gitlab/Github
52+
- POST /issues/recreate - recreate an issue DB and its challenge
53+
5154
## Configuration
5255

5356
please see [configuration.md](configuration.md).
@@ -63,11 +66,11 @@ Server should be started at port 80.
6366
## Heroku Deployment
6467
Follow the below steps to deploy the app to heroku
6568
1. `heroku login`
66-
1. `heroku create`
67-
1. `heroku addons:create mongolab`
68-
1. `heroku config:set NPM_CONFIG_PRODUCTION=false` so that heroku will install dev dependencies
69-
1. `git push heroku master` or `git push heroku develop:master` to deploy develop branch
70-
1. `heroku open` to load the app on browser
69+
2. `heroku create`
70+
3. `heroku addons:create mongolab`
71+
4. `heroku config:set NPM_CONFIG_PRODUCTION=false` so that heroku will install dev dependencies
72+
5. `git push heroku master` or `git push heroku develop:master` to deploy develop branch
73+
6. `heroku open` to load the app on browser
7174

7275
Note: heroku domain should match subdomain of topcoder-dev or topcoder depending upon target topcoder environment
7376

src/common/helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function buildController(controller) {
132132
* @returns {Error} converted error
133133
*/
134134
function convertGitHubError(err, message) {
135-
let resMsg = `${message}. ${err.message}.`;
135+
let resMsg = `${message}. ${err.message}.\n`;
136136
const detail = _.get(err, 'response.body.message');
137137
if (detail) {
138138
resMsg += ` Detail: ${detail}`;
@@ -152,7 +152,7 @@ function convertGitHubError(err, message) {
152152
* @returns {Error} converted error
153153
*/
154154
function convertGitLabError(err, message) {
155-
let resMsg = `${message}. ${err.message}.`;
155+
let resMsg = `${message}. ${err.message}.\n`;
156156
const detail = _.get(err, 'response.body.message');
157157
if (detail) {
158158
resMsg += ` Detail: ${detail}`;

src/config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright (c) 2017 TopCoder, Inc. All rights reserved.
33
*/
4-
const fs = require('fs');
4+
// const fs = require('fs');
55
/**
66
* Define config.
77
*
@@ -27,11 +27,11 @@ module.exports = {
2727
TOPIC: process.env.TOPIC || 'tc-x-events',
2828
KAFKA_OPTIONS: {
2929
connectionString: process.env.KAFKA_URL || 'localhost:9092',
30-
ssl: {
31-
cert: process.env.KAFKA_CLIENT_CERT || fs.readFileSync('./kafka_client.cer'), // eslint-disable-line no-sync
32-
key: process.env.KAFKA_CLIENT_CERT_KEY || fs.readFileSync('./kafka_client.key'), // eslint-disable-line no-sync
33-
passphrase: 'secret', // NOTE:* This configuration specifies the private key passphrase used while creating it.
34-
},
30+
// ssl: {
31+
// cert: process.env.KAFKA_CLIENT_CERT || fs.readFileSync('./kafka_client.cer'), // eslint-disable-line no-sync
32+
// key: process.env.KAFKA_CLIENT_CERT_KEY || fs.readFileSync('./kafka_client.key'), // eslint-disable-line no-sync
33+
// passphrase: 'secret', // NOTE:* This configuration specifies the private key passphrase used while creating it.
34+
// },
3535
},
3636
HOOK_BASE_URL: process.env.HOOK_BASE_URL || 'http://topcoderx.topcoder-dev.com',
3737
TOPCODER_ENV: process.env.TOPCODER_ENV || 'dev',

src/controllers/IssueController.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,22 @@ async function create(req) {
3131
return await IssueService.create(req.body, req.currentUser);
3232
}
3333

34+
/**
35+
* recreate an issue
36+
* Remove the related db record.
37+
* Recreate new record and create new challenge.
38+
* @param {Object} req the request
39+
* @param {Object} res the response
40+
* @returns {Object} the result
41+
*/
42+
async function recreate(req) {
43+
return await IssueService.recreate(req.body, req.currentUser);
44+
}
45+
3446
module.exports = {
3547
search,
36-
create
48+
create,
49+
recreate
3750
};
3851

3952
helper.buildController(module.exports);

src/front/src/app/auth/auth.service.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ angular.module('topcoderX')
151151
// save loggingOut promise to be accessed any time
152152
AuthService.logginOut = proxyCall(LOGOUT_REQUEST, LOGOUT_SUCCESS, LOGOUT_FAILURE).then(function () {
153153
AuthService.logginOut = null;
154+
// remove only token V3, which we set from the script manually
155+
// token V2 will be removed automatically during logout server request
156+
$cookies.remove(JWT_V3_NAME, { path: '/' });
154157
});
155-
// remove only token V3, which we set from the script manually
156-
// token V2 will be removed automatically during logout server request
157-
$cookies.remove(JWT_V3_NAME);
158158

159159
return AuthService.logginOut;
160160
}

src/front/src/app/main/issue.service.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,15 @@ angular.module('topcoderX')
2929
});
3030
};
3131

32+
/**
33+
* Recreate an Issue
34+
* @param issue the issue to be created
35+
*/
36+
service.recreate = function (issue) {
37+
return $http.post(Helper.baseUrl + '/api/v1/issues/recreate', issue).then(function (response) {
38+
return response;
39+
});
40+
};
41+
3242
return service;
3343
}]);

src/front/src/app/settings/settings.controller.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ angular.module('topcoderX').controller('SettingController', ['currentUser', '$sc
2626

2727
// Revoke gitlab or github account
2828
$scope.revoke = function(provider) {
29+
$rootScope.dialog = {
30+
proceed: false
31+
};
2932
$scope.$on('dialog.finished', function (event, args) {
3033
if (args.proceed) {
3134
SettingService.revokeUserSetting(currentUser.handle, provider).then(function () {

src/front/src/app/upsertissue/upsertissue.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h2>{{title}}</h2>
2121
<br />
2222
<br />
2323
<label class="form-label">Prize ($):</label>
24-
<input class="form-control" type="number" ng-model="issue.prize" required />
24+
<input class="form-control" type="number" ng-model="issue.prize" min="0" required />
2525
<small class="form-hint">The price amount of the issue</small>
2626
<span ng-show="issueForm.issue.prize.$touched && issueForm.issue.prize.$invalid">The
2727
price is required.</span>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// controller for transfer ownership dialog
2+
'use strict';
3+
4+
angular.module('topcoderX')
5+
.controller('RecreateDialogController', [
6+
'$scope', '$rootScope', '$state', '$uibModalInstance', 'IssueService', 'Alert', 'appConfig', 'project', '$log',
7+
function ($scope, $rootScope, $state, $uibModalInstance, IssueService, Alert, appConfig, project, $log) {
8+
// The user list
9+
$scope.project = project;
10+
$scope.appConfig = appConfig;
11+
12+
/**
13+
* transfer the ownership
14+
*/
15+
$scope.recreate = function () {
16+
if (!$scope.url) {
17+
Alert.error('The ticket URL is required', $scope);
18+
return;
19+
}
20+
var issueNumber;
21+
$log.log($scope.url);
22+
var ticketURL = new URL($scope.url);
23+
$log.log(ticketURL);
24+
if (ticketURL.pathname) {
25+
$log.log('asda');
26+
var paths = ticketURL.pathname.split('/');
27+
$log.log(paths);
28+
if (paths && paths.length > 0) {
29+
$log.log('fafa');
30+
issueNumber = parseInt(paths[paths.length - 1], 10);
31+
$log.log(issueNumber);
32+
}
33+
}
34+
if (!issueNumber) {
35+
Alert.error('The ticket URL is not valid', $scope);
36+
return;
37+
}
38+
var issue = {
39+
projectId: $scope.project.id,
40+
url: $scope.url,
41+
number: issueNumber
42+
};
43+
IssueService.recreate(issue).then(function () {
44+
Alert.info('<a href="' + $scope.url+ '" target="_blank"><b><u>Issue #' + issue.number + '</u></b></a> has been recreated', $scope);
45+
$rootScope.project = project;
46+
$uibModalInstance.close();
47+
}).catch(function (error) {
48+
Alert.error(error.data.message, $scope);
49+
});
50+
51+
// ProjectService.transferOwnership($scope.project.id, $scope.owner).then(function () {
52+
// Alert.info('Project ownership is transferred Successfully', $rootScope);
53+
// $rootScope.project = project;
54+
// $rootScope.project.owner = $scope.owner;
55+
// $state.go('app.project');
56+
// $uibModalInstance.close();
57+
// }).catch(function (error) {
58+
// Alert.error(error.data.message, $scope);
59+
// });
60+
};
61+
62+
/**
63+
* Close dialog
64+
*/
65+
$scope.close = function () {
66+
$uibModalInstance.close();
67+
};
68+
},
69+
]);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<div class="inmodal">
2+
<div class="modal-header">
3+
<button type="button" class="close" aria-label="Close" ng-click="close()">
4+
<span aria-hidden="true">&times;</span>
5+
</button>
6+
<h4 class="modal-title" id="reg-dialog-label">Recreate an Issue</h4>
7+
</div>
8+
<div class="modal-body" style="background-color: #fff;">
9+
<div class="row">
10+
<label class="form-label">Issue URL:</label>
11+
<input class="form-control" type="text" ng-model="url" required />
12+
<br />
13+
</div>
14+
<div class="row">
15+
<div class="col-md-10 col-md-offset-1" ng-include src="'components/alert/alert.html'"></div>
16+
</div>
17+
</div>
18+
<div class="modal-footer">
19+
<button type="button" class="btn btn-info" ng-click="recreate()">
20+
OK
21+
</button>
22+
<button type="button" class="btn btn-white" ng-click="close()">
23+
Cancel
24+
</button>
25+
</div>
26+
</div>

src/front/src/app/upsertproject/upsertproject.controller.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,25 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
9494
}
9595
};
9696

97+
$scope.openRecreateDialog = function () {
98+
$uibModal.open({
99+
size: 'md',
100+
templateUrl: 'app/upsertproject/recreate-dialog.html',
101+
controller: 'RecreateDialogController',
102+
resolve: {
103+
currentUser: function () {
104+
return currentUser;
105+
},
106+
appConfig: function () {
107+
return $rootScope.appConfig;
108+
},
109+
project: function () {
110+
return $scope.project;
111+
},
112+
},
113+
});
114+
};
115+
97116
$scope.openTransferOwnershipDialog = function () {
98117
$uibModal.open({
99118
size: 'md',

src/front/src/app/upsertproject/upsertproject.html

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,38 @@
44
<div class="col-lg-4">
55
<h2>{{title}}</h2>
66
</div>
7-
<div class="pull-right col-lg-5" ng-if="editing">
8-
<div class="col-lg-3" ng-if="!isAdminUser"></div>
9-
<div class="col-lg-3 with-button">
7+
<div class="pull-right col-lg-8" ng-if="editing">
8+
<div class="col-lg-2" ng-if="!isAdminUser"></div>
9+
<div class="col-lg-2 with-button">
10+
<button class="btn btn-sm btn-info" ng-click="openRecreateDialog()">
11+
<strong>Recreate an Issue</strong>
12+
</button>
13+
</div>
14+
<div class="col-lg-2 with-button">
15+
<button class="btn btn-sm btn-info" ng-click="addLabels()">
16+
<strong>Add Labels</strong>
17+
</button>
18+
</div>
19+
<div class="col-lg-2 with-button">
1020
<button class="btn btn-sm btn-info" ng-click="addLabels()">
1121
<strong>Add Labels</strong>
1222
</button>
1323
</div>
14-
<div class="col-lg-3 with-button">
24+
<div class="col-lg-2 with-button">
1525
<button class="btn btn-sm btn-info" ng-click="addHooks()">
1626
<strong>
1727
Add Webhook
1828
</strong>
1929
</button>
2030
</div>
21-
<div class="col-lg-3 with-button">
31+
<div class="col-lg-2 with-button">
2232
<button class="btn btn-sm btn-info" ng-click="addWikiRules()">
2333
<strong>
2434
Add Wiki Rules
2535
</strong>
2636
</button>
2737
</div>
28-
<div class="col-lg-3 with-button" ng-if="isAdminUser">
38+
<div class="col-lg-2 with-button" ng-if="isAdminUser">
2939
<button class="btn btn-sm btn-info" ng-click="openTransferOwnershipDialog()">
3040
<strong>
3141
Transfer ownership

src/routes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ module.exports = {
214214
method: 'create',
215215
},
216216
},
217+
'/issues/recreate': {
218+
post: {
219+
controller: 'IssueController',
220+
method: 'recreate'
221+
}
222+
},
217223
'/appConfig': {
218224
get: {
219225
controller: 'AppConfigController',

0 commit comments

Comments
 (0)