Skip to content

Commit fe691ed

Browse files
committed
fix: pr review
1 parent 3c42f80 commit fe691ed

10 files changed

Lines changed: 87 additions & 102 deletions

File tree

messages/commonErrors.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ Connection is required
4545
# error.query-string-required
4646

4747
Query string is required and must be a non-empty string
48+
49+
# error.DevopsCenterNotEnabled
50+
51+
DevOps Center is not enabled in this org. Enable DevOps Center in Setup before using this command.

messages/devops.project.list.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ List all DevOps Center projects in a Salesforce org.
66

77
This command queries the DevopsProject standard object and returns the project Id, Name, and Description for each project found.
88

9-
# flags.target-org.summary
10-
11-
Username or alias of the DevOps Center org.
12-
139
# examples
1410

1511
- List all DevOps Center projects in an org with alias "my-devops-org":

messages/devops.work-item.create.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ Create a new work item in a DevOps Center project.
44

55
# description
66

7-
The command creates the work item using the Connect API. Requires a project ID and a subject for the new work item; run the `devops project list` command to get the IDs for all existing projects.
8-
9-
# flags.target-org.summary
10-
11-
Username or alias of the DevOps Center org.
7+
The command creates the work item using the Connect API. Requires a project ID and a subject for the new work item; run the `devops project list` command to get the IDs for all existing projects.
128

139
# flags.project-id.summary
1410

@@ -20,11 +16,11 @@ Subject (title) of the new work item.
2016

2117
# flags.description.summary
2218

23-
Description of the new work item; if not specified, the description is blank.
19+
Description of the new work item; if not specified, the description is blank.
2420

2521
# examples
2622

27-
- Create a work item for the project with the specified ID and give the work item the specified subject (title); use the DevOps Center org with alias "my-devops-org":
23+
- Create a work item for the project with the specified ID and give the work item the specified subject (title); use the DevOps Center org with alias "my-devops-org":
2824

2925
<%= config.bin %> <%= command.id %> --target-org my-devops-org --project-id 0Hn000000000001 --subject "Fix login bug"
3026

messages/devops.work-item.list.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ List all work items for a DevOps Center project.
44

55
# description
66

7-
Each work item displays the branch, environment, and repository details needed for checkout and promotion. Requires a project ID; run the `devops project list` command to get the IDs for all existing projects.
8-
9-
# flags.target-org.summary
10-
11-
Username or alias of the DevOps Center org.
7+
Each work item displays the branch, environment, and repository details needed for checkout and promotion. Requires a project ID; run the `devops project list` command to get the IDs for all existing projects.
128

139
# flags.project-id.summary
1410

src/commands/devops/project/list.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
import { Messages, Org } from '@salesforce/core';
99
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
10-
import { ux } from '@oclif/core';
1110

1211
Messages.importMessagesDirectory(__dirname);
1312
const messages = Messages.loadMessages('@salesforce/plugin-devops-center', 'devops.project.list');
13+
const commonErrorMessages = Messages.loadMessages('@salesforce/plugin-devops-center', 'commonErrors');
1414

1515
export type DevopsProject = {
1616
Id: string;
@@ -28,17 +28,14 @@ export default class DevopsProjectList extends SfCommand<DevopsProjectListResult
2828
public static readonly examples = messages.getMessages('examples');
2929

3030
public static readonly flags = {
31-
'target-org': Flags.requiredOrg({
32-
summary: messages.getMessage('flags.target-org.summary'),
33-
char: 'o',
34-
required: true,
35-
}),
31+
'target-org': Flags.requiredOrg(),
32+
'api-version': Flags.orgApiVersion(),
3633
};
3734

3835
public async run(): Promise<DevopsProjectListResult> {
3936
const { flags } = await this.parse(DevopsProjectList);
4037
const org: Org = flags['target-org'];
41-
const connection = org.getConnection('65.0');
38+
const connection = org.getConnection(flags['api-version']);
4239

4340
let projects: DevopsProject[];
4441
try {
@@ -48,18 +45,16 @@ export default class DevopsProjectList extends SfCommand<DevopsProjectListResult
4845
} catch (error: unknown) {
4946
const errMsg = error instanceof Error ? error.message : String(error);
5047
if (errMsg.includes('sObject type') && errMsg.includes('is not supported')) {
51-
this.error(
52-
'DevOps Center is not enabled in this org. Enable DevOps Center in Setup before using this command.'
53-
);
48+
this.error(commonErrorMessages.getMessage('error.DevopsCenterNotEnabled'));
5449
}
5550
throw error;
5651
}
5752

5853
if (projects.length === 0) {
5954
this.log('No DevOps Center projects found in this org.');
6055
} else {
61-
ux.styledHeader('DevOps Center Projects');
62-
ux.table(projects, {
56+
this.styledHeader('DevOps Center Projects');
57+
this.table(projects, {
6358
Id: { header: 'Id' },
6459
Name: { header: 'Name' },
6560
Description: { header: 'Description' },

src/commands/devops/work-item/create.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,21 @@ import { createWorkItem, CreateWorkItemResult } from '../../../utils/createWorkI
1111

1212
Messages.importMessagesDirectory(__dirname);
1313
const messages = Messages.loadMessages('@salesforce/plugin-devops-center', 'devops.work-item.create');
14+
const commonErrorMessages = Messages.loadMessages('@salesforce/plugin-devops-center', 'commonErrors');
1415

1516
export default class DevopsWorkItemCreate extends SfCommand<CreateWorkItemResult> {
1617
public static readonly summary = messages.getMessage('summary');
1718
public static readonly description = messages.getMessage('description');
1819
public static readonly examples = messages.getMessages('examples');
1920

2021
public static readonly flags = {
21-
'target-org': Flags.requiredOrg({
22-
summary: messages.getMessage('flags.target-org.summary'),
23-
char: 'o',
24-
required: true,
25-
}),
26-
'project-id': Flags.string({
22+
'target-org': Flags.requiredOrg(),
23+
'api-version': Flags.orgApiVersion(),
24+
'project-id': Flags.salesforceId({
2725
summary: messages.getMessage('flags.project-id.summary'),
2826
char: 'p',
2927
required: true,
28+
startsWith: '1Qg',
3029
}),
3130
subject: Flags.string({
3231
summary: messages.getMessage('flags.subject.summary'),
@@ -42,7 +41,7 @@ export default class DevopsWorkItemCreate extends SfCommand<CreateWorkItemResult
4241
public async run(): Promise<CreateWorkItemResult> {
4342
const { flags } = await this.parse(DevopsWorkItemCreate);
4443
const org: Org = flags['target-org'];
45-
const connection = org.getConnection('65.0');
44+
const connection = org.getConnection(flags['api-version']);
4645

4746
let result: CreateWorkItemResult;
4847
try {
@@ -55,9 +54,7 @@ export default class DevopsWorkItemCreate extends SfCommand<CreateWorkItemResult
5554
} catch (error: unknown) {
5655
const errMsg = error instanceof Error ? error.message : String(error);
5756
if (errMsg.includes('sObject type') && errMsg.includes('is not supported')) {
58-
this.error(
59-
'DevOps Center is not enabled in this org. Enable DevOps Center in Setup before using this command.'
60-
);
57+
this.error(commonErrorMessages.getMessage('error.DevopsCenterNotEnabled'));
6158
}
6259
throw error;
6360
}

src/commands/devops/work-item/list.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
import { Messages, Org } from '@salesforce/core';
99
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
10-
import { ux } from '@oclif/core';
1110
import { fetchWorkItems } from '../../../utils/workItems';
1211
import { WorkItem } from '../../../utils/types';
1312

1413
Messages.importMessagesDirectory(__dirname);
1514
const messages = Messages.loadMessages('@salesforce/plugin-devops-center', 'devops.work-item.list');
15+
const commonErrorMessages = Messages.loadMessages('@salesforce/plugin-devops-center', 'commonErrors');
1616

1717
export type DevopsWorkItemListResult = {
1818
workItems: WorkItem[];
@@ -24,33 +24,29 @@ export default class DevopsWorkItemList extends SfCommand<DevopsWorkItemListResu
2424
public static readonly examples = messages.getMessages('examples');
2525

2626
public static readonly flags = {
27-
'target-org': Flags.requiredOrg({
28-
summary: messages.getMessage('flags.target-org.summary'),
29-
char: 'o',
30-
required: true,
31-
}),
32-
'project-id': Flags.string({
27+
'target-org': Flags.requiredOrg(),
28+
'api-version': Flags.orgApiVersion(),
29+
'project-id': Flags.salesforceId({
3330
summary: messages.getMessage('flags.project-id.summary'),
3431
char: 'p',
3532
required: true,
33+
startsWith: '1Qg',
3634
}),
3735
};
3836

3937
public async run(): Promise<DevopsWorkItemListResult> {
4038
const { flags } = await this.parse(DevopsWorkItemList);
4139
const org: Org = flags['target-org'];
4240
const projectId: string = flags['project-id'];
43-
const connection = org.getConnection('65.0');
41+
const connection = org.getConnection(flags['api-version']);
4442

4543
let workItems: WorkItem[];
4644
try {
4745
workItems = await fetchWorkItems(connection, projectId);
4846
} catch (error: unknown) {
4947
const errMsg = error instanceof Error ? error.message : String(error);
5048
if (errMsg.includes('sObject type') && errMsg.includes('is not supported')) {
51-
this.error(
52-
'DevOps Center is not enabled in this org. Enable DevOps Center in Setup before using this command.'
53-
);
49+
this.error(commonErrorMessages.getMessage('error.DevopsCenterNotEnabled'));
5450
}
5551
throw error;
5652
}
@@ -66,8 +62,8 @@ export default class DevopsWorkItemList extends SfCommand<DevopsWorkItemListResu
6662
'Target Branch': wi.TargetBranch ?? '',
6763
}));
6864

69-
ux.styledHeader('DevOps Center Work Items');
70-
ux.table(tableData, {
65+
this.styledHeader('DevOps Center Work Items');
66+
this.table(tableData, {
7167
Name: { header: 'Name' },
7268
Subject: { header: 'Subject' },
7369
Status: { header: 'Status' },

src/utils/pipelineUtils.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,18 @@
66
*/
77

88
import { Connection } from '@salesforce/core';
9-
import { PipelineStageRecord } from './types';
9+
import { DevopsProjectPipelineQueryRecord, PipelineStageRecord } from './types';
1010

1111
export async function getPipelineIdForProject(connection: Connection, projectId: string): Promise<string | undefined> {
1212
const query = `SELECT DevopsPipelineId FROM DevopsProjectPipeline WHERE DevopsProjectId = '${projectId}' LIMIT 1`;
13-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14-
const result: any = await connection.query(query);
15-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
16-
return (result?.records ?? [])[0]?.DevopsPipelineId;
13+
const result = await connection.query<DevopsProjectPipelineQueryRecord>(query);
14+
return result.records[0]?.DevopsPipelineId;
1715
}
1816

1917
export async function fetchPipelineStages(connection: Connection, pipelineId: string): Promise<PipelineStageRecord[]> {
2018
const stageQuery = `SELECT Id, Name, NextStageId, SourceCodeRepositoryBranch.Name FROM DevopsPipelineStage WHERE DevopsPipelineId = '${pipelineId}'`;
21-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
22-
const stageResult: any = await connection.query(stageQuery);
23-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
24-
return (stageResult?.records ?? []) as PipelineStageRecord[];
19+
const stageResult = await connection.query<PipelineStageRecord>(stageQuery);
20+
return stageResult.records ?? [];
2521
}
2622

2723
export function computeFirstStageId(stages: PipelineStageRecord[]): string | undefined {

src/utils/types.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,32 @@ export type ProjectStagesContext = {
3838
};
3939

4040
export type VcsType = 'GITHUB' | 'BITBUCKET';
41+
42+
export type SourceCodeRepositoryQueryRecord = {
43+
Name: string | null;
44+
RepositoryOwner: string | null;
45+
Provider: string | null;
46+
};
47+
48+
export type SourceCodeRepositoryBranchQueryRecord = {
49+
Name: string | null;
50+
SourceCodeRepositoryId: string | null;
51+
SourceCodeRepository: SourceCodeRepositoryQueryRecord | null;
52+
};
53+
54+
export type WorkItemQueryRecord = {
55+
Id: string;
56+
Name: string;
57+
Subject: string | null;
58+
Description: string | null;
59+
Status: string;
60+
AssignedToId: string | null;
61+
SourceCodeRepositoryBranchId: string | null;
62+
SourceCodeRepositoryBranch: SourceCodeRepositoryBranchQueryRecord | null;
63+
DevopsPipelineStageId: string | null;
64+
DevopsProjectId: string;
65+
};
66+
67+
export type DevopsProjectPipelineQueryRecord = {
68+
DevopsPipelineId: string;
69+
};

0 commit comments

Comments
 (0)