Skip to content

Commit

Permalink
Merge branch 'main' into NDT-458-Wrong-line-number-for-GIS-import
Browse files Browse the repository at this point in the history
  • Loading branch information
RRanath authored Sep 13, 2024
2 parents 588cb99 + ff86b64 commit f1a7fcb
Show file tree
Hide file tree
Showing 19 changed files with 306 additions and 76 deletions.
2 changes: 2 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ Add detailed description of the changes if the PR title isn't enough
-->

- [ ] Check to trigger automatic release process

- [ ] Check for automatic rebasing
44 changes: 44 additions & 0 deletions .github/workflows/detect-conflict.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Detect Merge Conflict

on:
pull_request_target:
types: [edited, synchronize]

jobs:
move-to-merge-conflict:
environment:
name: development
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Does PR have conflic
env:
HEAD_REF: ${{ github.event.pull_request.head.ref }}
id: check_conflict
run: |
git config user.name "CCBC Service Account"
git config user.email "116113628+ccbc-service-account@users.noreply.github.com"
git fetch origin
git checkout main
git pull origin main
git checkout "$HEAD_REF"
git pull origin "$HEAD_REF"
set -e
git merge main --no-commit --no-ff
MERGE_STATUS=$?
echo $MERGE_STATUS
echo "MERGE_STATUS=$MERGE_STATUS" >> $GITHUB_OUTPUT
- name: Save PR number
if: steps.check_conflict.outputs.MERGE_STATUS != 0
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
mkdir -p ./pr
echo $PR_NUMBER > ./pr/pr_number
- uses: actions/upload-artifact@v4
with:
name: pr_number
path: pr/
4 changes: 3 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ jobs:
const { owner, repo } = context.repo
const listOfBranches = [];
const prs = await github.rest.pulls.list({ owner, repo, state: 'open' });
const checkboxText = "[x] Check for automatic rebasing";
for (const pr of prs.data) {
// check if PR is rebaseable, not draft, and mergable before adding to list
const baseBranch = pr.base.ref;
Expand All @@ -91,7 +92,8 @@ jobs:
head: headBranch
});
if(comparison.data.behind_by > 0 && !pr.draft && pr.requested_reviewers.length > 0){
const checkboxChecked = pr.body.includes(checkboxText);
if(comparison.data.behind_by > 0 && !pr.draft && checkboxChecked){
listOfBranches.push(pr.head.ref);
}
}
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/move-on-merge-conlifct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Move Merge Conflict Tickets

on:
workflow_run:
workflows: ['Detect Merge Conflict']
types:
- completed

jobs:
get-feature-name:
environment:
name: development
runs-on: ubuntu-latest
steps:
- name: Download Artifact
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: context.payload.workflow_run.id
})
const matchArtifact = allArtifacts.data.filter(artifact => artifact.name === 'feature-name')[0]
const download = await github.rest.actions.downloadArtifact({
owner,
repo,
artifact_id: matchArtifact.id,
archive_format: 'zip'
})
const fs = require('fs')
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data))
- run: unzip pr_number.zip
- name: Check PR details and get feature name
id: get_feature_name
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const fs = require('fs')
const prNumber = Number(fs.readFileSync('pr/pr_number'))
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
})
if (pr.head.repo.fork){
return
}
const featureName = pr.head.ref
const regex = /NDT-\d+/g;
const match = featureName.match(regex)
return match
- name: Check Status of issue
if: startsWith(steps.get_feature_name.outputs.result, 'NDT-')
id: get_status
run: |
response=$(curl -s -X GET \
-H "Authorization: Basic ${{ secrets.JIRA_AUTH }}" \
-H "Content-Type: application/json" \
"https://connectivitydivision.atlassian.net/rest/api/3/issue/${{ steps.get_feature_name.outputs.result }}")
echo "Jira Key: $JIRA_KEY"
echo "Response: $response"
status=$(echo "$response" | jq -r '.fields.status.name')
echo "Issue status: $status"
echo "::set-output name=status::$status"
- name: Move to Merge Conflict Column
if: steps.get_status.outputs.status == 'PO REVIEW'
run: |
curl -X POST \
-H "Authorization: Basic ${{ secrets.JIRA_AUTH }}" \
-H "Content-Type: application/json" \
-d '{
"transition": {
"id": "9"
}
}' \
"https://connectivitydivision.atlassian.net/rest/api/3/issue/$JIRA_KEY/transitions"
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [1.190.12](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.190.11...v1.190.12) (2024-09-12)

### Bug Fixes

- remove unwanted status text from RFI ([a760e6d](https://github.com/bcgov/CONN-CCBC-portal/commit/a760e6d0a9d2510a1cbf07e5e2ac4c3b3dd8a151))

## [1.190.11](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.190.10...v1.190.11) (2024-09-12)

## [1.190.10](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.190.9...v1.190.10) (2024-09-10)

## [1.190.9](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.190.8...v1.190.9) (2024-09-06)
Expand Down
15 changes: 2 additions & 13 deletions app/backend/lib/emails/templates/assesmentSecondReviewChange.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
import ASSESSMENT_TYPES from '../../../../data/assessmentTypes';
import {
EmailTemplate,
EmailTemplateProvider,
} from '../handleEmailNotification';

const formats = {
projectManagement: {
type: 'Project Management assessment',
slug: 'project-management',
},
permitting: { type: 'Permitting assessment', slug: 'permitting' },
technical: { type: 'Technical assessment', slug: 'technical' },
gis: { type: 'GIS assessment', slug: 'gis' },
financialRisk: { type: 'Financial Risk assessment', slug: 'financial-risk' },
screening: { type: 'Eligibility Screening', slug: 'screening' },
};

const assesmentSecondReviewChange: EmailTemplateProvider = (
applicationId: string,
url: string,
initiator: any,
params: any
): EmailTemplate => {
const { ccbcNumber, assessmentType } = params;
const { type, slug } = formats[assessmentType];
const { type, slug } = ASSESSMENT_TYPES[assessmentType];

return {
emailTo: [34, 71], // Temporary IDs to handle email recipients
Expand Down
8 changes: 4 additions & 4 deletions app/backend/lib/emails/templates/assessmentAssigneeChange.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Context } from 'backend/lib/ches/sendEmailMerge';

import ASSESSMENT_TYPES from '../../../../data/assessmentTypes';
import {
EmailTemplate,
EmailTemplateProvider,
Expand Down Expand Up @@ -77,8 +77,8 @@ const assessmentAssigneeChange: EmailTemplateProvider = async (
([assignor, assignments]) => {
const alerts = (assignments as Array<any>).map((assignment) => {
return {
url: `${url}/analyst/application/${assignment.applicationId}/assessments/${assignment.assessmentType}`,
type: assignment.assessmentType,
url: `${url}/analyst/application/${assignment.applicationId}/assessments/${ASSESSMENT_TYPES[assignment.assessmentType].slug}`,
type: ASSESSMENT_TYPES[assignment.assessmentType].type,
ccbcNumber: assignment.ccbcNumber,
applicationId: assignment.applicationId,
};
Expand Down Expand Up @@ -121,7 +121,7 @@ const assessmentAssigneeChange: EmailTemplateProvider = async (
body: `{% for action in actions %}
{{ action.assignors }} has assigned you the following assessment(s):
<ul>{% for alert in action.alerts %}
<li><a href='{{ alert.url }}'>{{ alert.type | capitalize }}</a> for {{ alert.ccbcNumber }}</li>
<li><a href='{{ alert.url }}'>{{ alert.type }}</a> for {{ alert.ccbcNumber }}</li>
{% endfor %}</ul>
{% endfor %}`,
contexts,
Expand Down
123 changes: 77 additions & 46 deletions app/components/AnalystDashboard/AssessmentAssignmentTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useState } from 'react';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { graphql, useFragment } from 'react-relay';
import styled from 'styled-components';
import cookie from 'js-cookie';
Expand Down Expand Up @@ -148,6 +148,18 @@ const findAssessment = (assessments, assessmentType) => {
};
};

const findNotification = (notifications, notificationType) => {
const data = notifications.find(
({ node }) => node?.notificationType === notificationType
);

return {
jsonData: data?.node?.jsonData,
notificationType,
createdAt: data?.node?.createdAt,
};
};

const StyledLink = styled.a`
color: ${(props) => props.theme.color.links};
text-decoration: none;
Expand Down Expand Up @@ -235,11 +247,7 @@ const AssessmentAssignmentTable: React.FC<Props> = ({ query }) => {
}
}
}
notificationsByApplicationId(
orderBy: CREATED_AT_DESC
first: 1
condition: { notificationType: "assignment_technical" }
) {
assessmentNotifications {
__id
edges {
node {
Expand Down Expand Up @@ -429,9 +437,8 @@ const AssessmentAssignmentTable: React.FC<Props> = ({ query }) => {
zones,
allAnalysts,
assessmentConnection: application.allAssessments.__id,
notifications: application.notificationsByApplicationId.edges,
notificationConnectionId:
application.notificationsByApplicationId.__id,
application.assessmentNotifications?.__id,
pmAssessment: findAssessment(
application.allAssessments.edges,
'projectManagement'
Expand All @@ -440,6 +447,10 @@ const AssessmentAssignmentTable: React.FC<Props> = ({ query }) => {
application.allAssessments.edges,
'technical'
),
techNotification: findNotification(
application.assessmentNotifications.edges,
'assignment_technical'
),
permittingAssessment: findAssessment(
application.allAssessments.edges,
'permitting'
Expand All @@ -456,6 +467,10 @@ const AssessmentAssignmentTable: React.FC<Props> = ({ query }) => {
application.allAssessments.edges,
'financialRisk'
),
financialRiskNotification: findNotification(
application.assessmentNotifications.edges,
'assignment_financialRisk'
),
organizationName,
};
}
Expand All @@ -465,46 +480,62 @@ const AssessmentAssignmentTable: React.FC<Props> = ({ query }) => {
[allApplications, allAnalysts]
);

const getUserEmailByAssignedTo = (assignedTo: string) => {
const analyst = allAnalysts.edges.find(
({ node }) => `${node.givenName} ${node.familyName}` === assignedTo
);
return analyst ? analyst.node.email : null;
};

const assignments = useMemo(
() =>
tableData
.filter((data: any) => {
const lastSentAt = data.notifications[0]?.node?.createdAt
? new Date(data.notifications[0]?.node?.createdAt)
: null;
return new Date(data.techAssessment.updatedAt) >= lastSentAt;
})
.filter(
(data: any) =>
data.techAssessment.jsonData.assignedTo &&
data.techAssessment.jsonData.assignedTo !==
data.notifications[0]?.node?.jsonData?.to
)
.map((data: any) => {
return {
ccbcNumber: data.ccbcNumber,
applicationId: data.applicationId,
notificationConnectionId: data.notificationConnectionId,
updatedBy: data.techAssessment.updatedBy,
updatedAt: data.techAssessment.updatedAt,
assignedTo: data.techAssessment.jsonData?.assignedTo,
assigneeEmail: getUserEmailByAssignedTo(
data.techAssessment.jsonData?.assignedTo
),
assessmentType: 'technical',
};
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
[tableData]
const getUserEmailByAssignedTo = useCallback(
(assignedTo: string) => {
const analyst = allAnalysts.edges.find(
({ node }) => `${node.givenName} ${node.familyName}` === assignedTo
);
return analyst ? analyst.node.email : null;
},
[allAnalysts]
);

const assignments = useMemo(() => {
const createAssignment = (
application,
assessmentKey,
assessmentType = assessmentKey
) => {
const { updatedAt, jsonData, updatedBy } =
application[`${assessmentKey}Assessment`];
const notification = application[`${assessmentKey}Notification`];
const lastNotificationSentAt = notification?.createdAt
? new Date(notification.createdAt)
: null;

const assessmentChanged =
jsonData?.assignedTo &&
jsonData.assignedTo !== notification?.jsonData?.to;

if (new Date(updatedAt) >= lastNotificationSentAt && assessmentChanged) {
return {
ccbcNumber: application.ccbcNumber,
applicationId: application.applicationId,
notificationConnectionId: application.notificationConnectionId,
updatedBy,
updatedAt,
assignedTo: jsonData.assignedTo,
assigneeEmail: getUserEmailByAssignedTo(jsonData.assignedTo),
assessmentType,
};
}
return null;
};

return tableData.reduce((assignmentsList, application) => {
const techAssignment = createAssignment(application, 'tech', 'technical');
const financialAssignment = createAssignment(
application,
'financialRisk'
);

if (techAssignment) assignmentsList.push(techAssignment);
if (financialAssignment) assignmentsList.push(financialAssignment);

return assignmentsList;
}, []);
}, [getUserEmailByAssignedTo, tableData]);

const columns = useMemo<MRT_ColumnDef<Application>[]>(() => {
// Sonarcloud duplicate lines
const sharedAssessmentCell = {
Expand Down
Loading

0 comments on commit f1a7fcb

Please sign in to comment.