Skip to content

Commit

Permalink
chore: prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
Szandor72 committed Jan 16, 2024
1 parent ea161d5 commit 0ea2571
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 203 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/validate-code.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: Code Scans with SFDX Scanner

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- integration
paths:
- 'force-app/**'
pull_request:
types: [opened, synchronize, reopened]
branches:
- integration
paths:
- "force-app/**"

jobs:
sfdx-scanner:
name: 'Validate Code'
uses: 'Szandor72/devops-center-actions/.github/workflows/validate-code.yml@main'
secrets: inherit
sfdx-scanner:
name: "Validate Code"
uses: "Szandor72/devops-center-actions/.github/workflows/validate-code.yml@main"
secrets: inherit
20 changes: 10 additions & 10 deletions .github/workflows/validate-deployment.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: Validate Deployment

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- integration
paths:
- 'force-app/**'
pull_request:
types: [opened, synchronize, reopened]
branches:
- integration
paths:
- "force-app/**"

jobs:
validate-deployment:
name: 'SFDX Scanner'
uses: 'Szandor72/devops-center-actions/.github/workflows/validate-deployment.yml@main'
secrets: inherit
validate-deployment:
name: "SFDX Scanner"
uses: "Szandor72/devops-center-actions/.github/workflows/validate-deployment.yml@main"
secrets: inherit
18 changes: 9 additions & 9 deletions .github/workflows/validate-metadata.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Custom Metadata Checks

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- integration
paths:
- 'force-app/**'
pull_request:
types: [opened, synchronize, reopened]
branches:
- integration
paths:
- "force-app/**"

jobs:
validate-metadata:
name: 'Validate Metadata'
uses: 'Szandor72/devops-center-actions/.github/workflows/validate-metadata.yml@main'
validate-metadata:
name: "Validate Metadata"
uses: "Szandor72/devops-center-actions/.github/workflows/validate-metadata.yml@main"
20 changes: 10 additions & 10 deletions config/project-scratch-def.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"orgName": "Demo company",
"edition": "Developer",
"features": ["EnableSetPasswordInApi"],
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
},
"mobileSettings": {
"enableS1EncryptedStoragePref2": false
}
"orgName": "Demo company",
"edition": "Developer",
"features": ["EnableSetPasswordInApi"],
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
},
"mobileSettings": {
"enableS1EncryptedStoragePref2": false
}
}
}
132 changes: 68 additions & 64 deletions demo-classes/AccountService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,82 @@
* Provides various services related to Account object
*/
public class AccountService {
/**
* Fetches details for a given account
* @param accountId The ID of the account
* @return Account The details of the account
*/
public Account getAccDetails(Id accountId) {
// SOQL query inside a loop - bad practice
for (Id accId : new List<Id>{ accountId }) {
Account acc = [SELECT Id, Name, Industry FROM Account WHERE Id = :accId];
return acc;
}
return null;
/**
* Fetches details for a given account
* @param accountId The ID of the account
* @return Account The details of the account
*/
public Account getAccDetails(Id accountId) {
// SOQL query inside a loop - bad practice
for (Id accId : new List<Id>{ accountId }) {
Account acc = [SELECT Id, Name, Industry FROM Account WHERE Id = :accId];
return acc;
}
return null;
}

public Account getAccDetails2(Id accountId) {
// SOQL query inside a loop - bad practice
for (Id accId : new List<Id>{ accountId }) {
Account acc = [SELECT Id, Name, Industry FROM Account WHERE Id = :accId];
update acc;
return acc;
}
return null;
public Account getAccDetails2(Id accountId) {
// SOQL query inside a loop - bad practice
for (Id accId : new List<Id>{ accountId }) {
Account acc = [SELECT Id, Name, Industry FROM Account WHERE Id = :accId];
update acc;
return acc;
}
return null;
}

// This method lacks ApexDocs
public void UpdateAccount(List<Account> accounts) {
// DML operation inside a loop - bad practice
for (Account acc : accounts) {
acc.Name += ' - Updated';
update acc; // This should be done in bulk outside the loop
}
// This method lacks ApexDocs
public void UpdateAccount(List<Account> accounts) {
// DML operation inside a loop - bad practice
for (Account acc : accounts) {
acc.Name += ' - Updated';
update acc; // This should be done in bulk outside the loop
}
}

/**
* Deletes a specified account
* @param accountId The ID of the account to be deleted
*/
public void delete_Account(Id accountId) {
// Hardcoding IDs - bad practice
Id hardCodedId = '001xx000003DGAXAA4';
delete [SELECT Id FROM Account WHERE Id = :hardCodedId];
}
/**
* Deletes a specified account
* @param accountId The ID of the account to be deleted
*/
public void delete_Account(Id accountId) {
// Hardcoding IDs - bad practice
Id hardCodedId = '001xx000003DGAXAA4';
delete [SELECT Id FROM Account WHERE Id = :hardCodedId];
}

// This method lacks ApexDocs
public List<Account> ListAccounts() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}
// This method lacks ApexDocs
public List<Account> ListAccounts() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}

/**
* Calculates the annual revenue
* - This ApexDoc is incomplete and lacks parameter description
* @return Decimal The calculated annual revenue
*/
public String CalculateAnnualRevenue() {
// Lack of null checks and exception handling - bad practice
Account acc = [SELECT Industry FROM Account WHERE Id = '001xx000003DGAZAA4'];
return acc.Industry;
}
/**
* Calculates the annual revenue
* - This ApexDoc is incomplete and lacks parameter description
* @return Decimal The calculated annual revenue
*/
public String CalculateAnnualRevenue() {
// Lack of null checks and exception handling - bad practice
Account acc = [
SELECT Industry
FROM Account
WHERE Id = '001xx000003DGAZAA4'
];
return acc.Industry;
}

// This method lacks ApexDocs
public List<Account> ListAccounts2() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}
// This method lacks ApexDocs
public List<Account> ListAccounts2() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}

// This method lacks ApexDocs
public List<Account> ListAccounts3() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}
// This method lacks ApexDocs
public List<Account> ListAccounts3() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}
}
14 changes: 7 additions & 7 deletions demo-classes/CaseService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* @description service related updates
*/
public with sharing class CaseService {
public static void doUpdates(Set<Id> caseIds) {
List<Case> cases = [SELECT Id, Status FROM Case WHERE Id IN :caseIds];
for (Case c : cases) {
c.Status = 'Closed';
// raise pmd error
update c;
}
public static void doUpdates(Set<Id> caseIds) {
List<Case> cases = [SELECT Id, Status FROM Case WHERE Id IN :caseIds];
for (Case c : cases) {
c.Status = 'Closed';
// raise pmd error
update c;
}
}
}
114 changes: 58 additions & 56 deletions force-app/main/default/classes/ContentDocumentTriggerHandler.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,69 @@
* @description Handles legacy metadata scan file uploads from GitHub
*/
public with sharing class ContentDocumentTriggerHandler {
/**
* @description sends a notification for legacy scan file uploads
* @param newContentDocumentMap - received from trigger
*/
@SuppressWarnings('PMD.ApexCRUDViolation')
public static void notifyOnLegacyCodeScanFileUploads(
Map<Id, ContentDocument> newContentDocumentMap
/**
* @description sends a notification for legacy scan file uploads
* @param newContentDocumentMap - received from trigger
*/
@SuppressWarnings('PMD.ApexCRUDViolation')
public static void notifyOnLegacyCodeScanFileUploads(
Map<Id, ContentDocument> newContentDocumentMap
) {
Boolean isBulkOperation = newContentDocumentMap.values().size() > 1;
if (isBulkOperation) {
return;
}
List<CustomNotificationType> notificationTypes = [
SELECT Id, DeveloperName
FROM CustomNotificationType
WHERE DeveloperName = 'NewMetadataScanAvailable'
];
if (notificationTypes.isEmpty()) {
return;
}
CustomNotificationType notificationType = notificationTypes[0];
for (
ContentDocument matchingFile : filterContentDocuments(
newContentDocumentMap.values()
)
) {
Boolean isBulkOperation = newContentDocumentMap.values().size() > 1;
if (isBulkOperation) {
return;
}
List<CustomNotificationType> notificationTypes = [
SELECT Id, DeveloperName
FROM CustomNotificationType
WHERE DeveloperName = 'NewMetadataScanAvailable'
];
if (notificationTypes.isEmpty()) {
return;
}
CustomNotificationType notificationType = notificationTypes[0];
for (
ContentDocument matchingFile : filterContentDocuments(newContentDocumentMap.values())
) {
Messaging.CustomNotification notification = new Messaging.CustomNotification();
Messaging.CustomNotification notification = new Messaging.CustomNotification();

notification.setTitle('New Metadata Scan Available');
notification.setBody(
'Please review the scan and discuss necessary changes with the developer'
);
notification.setTitle('New Metadata Scan Available');
notification.setBody(
'Please review the scan and discuss necessary changes with the developer'
);

notification.setNotificationTypeId(notificationType.Id);
notification.setTargetId(matchingFile.Id);
notification.setNotificationTypeId(notificationType.Id);
notification.setTargetId(matchingFile.Id);

// TODO identify targets for notification, i.e. public group's first level members?
// uploading user should be a technical user
try {
notification.send(new Set<String>{ UserInfo.getUserId() });
} catch (Exception e) {
return;
}
}
// TODO identify targets for notification, i.e. public group's first level members?
// uploading user should be a technical user
try {
notification.send(new Set<String>{ UserInfo.getUserId() });
} catch (Exception e) {
return;
}
}
}

/**
* @description Filter ContentDocument sobjects by file extension and title
* @param contentDocuments list of ContentDocument sobjects to filter
* @return matchingContentDocuments
*/
public static List<ContentDocument> filterContentDocuments(
List<ContentDocument> contentDocuments
) {
List<ContentDocument> matchingContentDocuments = new List<ContentDocument>();
for (ContentDocument uploadedFile : contentDocuments) {
if (
String.isNotBlank(uploadedFile.Title) &&
uploadedFile.Title.contains('legacy-scan-results_')
) {
matchingContentDocuments.add(uploadedFile);
}
}
return matchingContentDocuments;
/**
* @description Filter ContentDocument sobjects by file extension and title
* @param contentDocuments list of ContentDocument sobjects to filter
* @return matchingContentDocuments
*/
public static List<ContentDocument> filterContentDocuments(
List<ContentDocument> contentDocuments
) {
List<ContentDocument> matchingContentDocuments = new List<ContentDocument>();
for (ContentDocument uploadedFile : contentDocuments) {
if (
String.isNotBlank(uploadedFile.Title) &&
uploadedFile.Title.contains('legacy-scan-results_')
) {
matchingContentDocuments.add(uploadedFile);
}
}
return matchingContentDocuments;
}
}
Loading

0 comments on commit 0ea2571

Please sign in to comment.