Skip to content

feat(PM-1173): Notify all copilots on copilot opportunity #815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
deploy feature branch
  • Loading branch information
hentrymartin committed Jun 2, 2025
commit 0c54ecf674f59efc9eceb2b9c286aacb0696fde1
3 changes: 3 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ export const CONNECT_NOTIFICATION_EVENT = {
TOPIC_UPDATED: 'connect.notification.project.topic.updated',
POST_CREATED: 'connect.notification.project.post.created',
POST_UPDATED: 'connect.notification.project.post.edited',

// Copilot events
COPILOT_OPPORTUNITY_CREATED: 'connect.notification.project.copilot.opportunity.created',
};

export const REGEX = {
Expand Down
4 changes: 3 additions & 1 deletion src/routes/copilotRequest/approveRequest.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ module.exports = (data, existingTransaction) => {
.then((opportunity) => {
console.log(opportunity);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using console.log for debugging in production code. Consider using a logging library to handle logs appropriately.

const roles = util.getRolesByRoleName('copilot');
console.log(roles, 'roles by copilot');
const roleInfo = util.getRoleInfo(roles[0]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider checking if roles is not empty before accessing roles[0] to avoid potential runtime errors.

console.log(roles, roleInfo, 'roles by copilot');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing the console.log(roles, roleInfo, 'roles by copilot'); statement if it's not necessary for debugging. Console logs can clutter the output and should be avoided in production code.


return opportunity;
})
.catch((err) => {
Expand Down
23 changes: 22 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,27 @@ const projectServiceUtils = {
}
},

getRoleInfo: Promise.coroutine(function* (roleId, logger, requestId) { // eslint-disable-line func-names
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using async/await syntax instead of Promise.coroutine for better readability and modern JavaScript practices.

try {
const token = yield this.getM2MToken();
const httpClient = this.getHttpClient({ id: requestId, log: logger });
return httpClient.get(`${config.identityServiceEndpoint}roles/${roleId}`, {
params: {
fields: 'subjects'
},
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
}).then((res) => {
logger.debug(`Role info by ${roleId}: ${JSON.stringify(res.data.result.content)}`);
return _.get(res, 'data.result.content', []);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of _.get is good for safely accessing nested properties, but ensure that lodash is imported as _ at the top of the file if not already done.

});
} catch (err) {
return Promise.reject(err);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of returning Promise.reject(err), consider using throw err; to maintain consistency with async/await error handling patterns.

}
}),

getRolesByRoleName: Promise.coroutine(function* (roleName, logger, requestId) { // eslint-disable-line func-names
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using async/await instead of Promise.coroutine for better readability and modern syntax.

try {
const token = yield this.getM2MToken();
Expand All @@ -829,7 +850,7 @@ const projectServiceUtils = {
},
}).then((res) => {
logger.debug(`Roles by ${roleName}: ${JSON.stringify(res.data.result.content)}`);
return _.get(res, 'data.result.content', []).map(r => r.roleName);
return _.get(res, 'data.result.content', []).map(r => r.id);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from r.roleName to r.id alters the data being returned by the map function. Ensure that this change aligns with the intended functionality and that any dependent code is updated accordingly to handle the new data structure.

});
} catch (err) {
return Promise.reject(err);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of catching the error and returning a rejected promise, consider allowing the error to propagate naturally. This will make the function easier to handle with async/await syntax.

Expand Down