Skip to content

Commit b58fd19

Browse files
committed
bugfix-319-setup-crash-on-repository-with-no-issues: extract content block index calculation into a new private helper method.
1 parent 2dd364d commit b58fd19

5 files changed

Lines changed: 63 additions & 54 deletions

File tree

build/cli/index.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52775,16 +52775,11 @@ class ContentInterface {
5277552775
if (description === undefined) {
5277652776
return undefined;
5277752777
}
52778-
const startIndex = description.indexOf(this.startPattern);
52779-
if (startIndex === -1) {
52778+
const indices = this.getBlockIndices(description);
52779+
if (!indices) {
5278052780
return undefined;
5278152781
}
52782-
const contentStart = startIndex + this.startPattern.length;
52783-
const endIndex = description.indexOf(this.endPattern, contentStart);
52784-
if (endIndex === -1) {
52785-
return undefined;
52786-
}
52787-
return description.substring(contentStart, endIndex);
52782+
return description.substring(indices.contentStart, indices.endIndex);
5278852783
}
5278952784
catch (error) {
5279052785
(0, logger_1.logError)(`Error reading issue configuration: ${error}`);
@@ -52801,20 +52796,14 @@ class ContentInterface {
5280152796
}
5280252797
};
5280352798
this._updateContent = (description, content) => {
52804-
const startIndex = description.indexOf(this.startPattern);
52805-
if (startIndex === -1) {
52806-
(0, logger_1.logError)(`The content has a problem with open-close tags: ${this.startPattern} / ${this.endPattern}`);
52807-
return undefined;
52808-
}
52809-
const contentStart = startIndex + this.startPattern.length;
52810-
const endIndex = description.indexOf(this.endPattern, contentStart);
52811-
if (endIndex === -1) {
52799+
const indices = this.getBlockIndices(description);
52800+
if (!indices) {
5281252801
(0, logger_1.logError)(`The content has a problem with open-close tags: ${this.startPattern} / ${this.endPattern}`);
5281352802
return undefined;
5281452803
}
52815-
const start = description.substring(0, startIndex);
52804+
const start = description.substring(0, indices.startIndex);
5281652805
const mid = `${this.startPattern}\n${content}\n${this.endPattern}`;
52817-
const end = description.substring(endIndex + this.endPattern.length);
52806+
const end = description.substring(indices.endIndex + this.endPattern.length);
5281852807
return `${start}${mid}${end}`;
5281952808
};
5282052809
this.updateContent = (description, content) => {
@@ -52849,6 +52838,18 @@ class ContentInterface {
5284952838
}
5285052839
return `${this._id}-end -->`;
5285152840
}
52841+
getBlockIndices(description) {
52842+
const startIndex = description.indexOf(this.startPattern);
52843+
if (startIndex === -1) {
52844+
return undefined;
52845+
}
52846+
const contentStart = startIndex + this.startPattern.length;
52847+
const endIndex = description.indexOf(this.endPattern, contentStart);
52848+
if (endIndex === -1) {
52849+
return undefined;
52850+
}
52851+
return { startIndex, contentStart, endIndex };
52852+
}
5285252853
}
5285352854
exports.ContentInterface = ContentInterface;
5285452855

build/cli/src/manager/description/base/content_interface.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export declare abstract class ContentInterface {
44
abstract get visibleContent(): boolean;
55
private get startPattern();
66
private get endPattern();
7+
private getBlockIndices;
78
getContent: (description: string | undefined) => string | undefined;
89
private _addContent;
910
private _updateContent;

build/github_action/index.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47856,16 +47856,11 @@ class ContentInterface {
4785647856
if (description === undefined) {
4785747857
return undefined;
4785847858
}
47859-
const startIndex = description.indexOf(this.startPattern);
47860-
if (startIndex === -1) {
47859+
const indices = this.getBlockIndices(description);
47860+
if (!indices) {
4786147861
return undefined;
4786247862
}
47863-
const contentStart = startIndex + this.startPattern.length;
47864-
const endIndex = description.indexOf(this.endPattern, contentStart);
47865-
if (endIndex === -1) {
47866-
return undefined;
47867-
}
47868-
return description.substring(contentStart, endIndex);
47863+
return description.substring(indices.contentStart, indices.endIndex);
4786947864
}
4787047865
catch (error) {
4787147866
(0, logger_1.logError)(`Error reading issue configuration: ${error}`);
@@ -47882,20 +47877,14 @@ class ContentInterface {
4788247877
}
4788347878
};
4788447879
this._updateContent = (description, content) => {
47885-
const startIndex = description.indexOf(this.startPattern);
47886-
if (startIndex === -1) {
47887-
(0, logger_1.logError)(`The content has a problem with open-close tags: ${this.startPattern} / ${this.endPattern}`);
47888-
return undefined;
47889-
}
47890-
const contentStart = startIndex + this.startPattern.length;
47891-
const endIndex = description.indexOf(this.endPattern, contentStart);
47892-
if (endIndex === -1) {
47880+
const indices = this.getBlockIndices(description);
47881+
if (!indices) {
4789347882
(0, logger_1.logError)(`The content has a problem with open-close tags: ${this.startPattern} / ${this.endPattern}`);
4789447883
return undefined;
4789547884
}
47896-
const start = description.substring(0, startIndex);
47885+
const start = description.substring(0, indices.startIndex);
4789747886
const mid = `${this.startPattern}\n${content}\n${this.endPattern}`;
47898-
const end = description.substring(endIndex + this.endPattern.length);
47887+
const end = description.substring(indices.endIndex + this.endPattern.length);
4789947888
return `${start}${mid}${end}`;
4790047889
};
4790147890
this.updateContent = (description, content) => {
@@ -47930,6 +47919,18 @@ class ContentInterface {
4793047919
}
4793147920
return `${this._id}-end -->`;
4793247921
}
47922+
getBlockIndices(description) {
47923+
const startIndex = description.indexOf(this.startPattern);
47924+
if (startIndex === -1) {
47925+
return undefined;
47926+
}
47927+
const contentStart = startIndex + this.startPattern.length;
47928+
const endIndex = description.indexOf(this.endPattern, contentStart);
47929+
if (endIndex === -1) {
47930+
return undefined;
47931+
}
47932+
return { startIndex, contentStart, endIndex };
47933+
}
4793347934
}
4793447935
exports.ContentInterface = ContentInterface;
4793547936

build/github_action/src/manager/description/base/content_interface.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export declare abstract class ContentInterface {
44
abstract get visibleContent(): boolean;
55
private get startPattern();
66
private get endPattern();
7+
private getBlockIndices;
78
getContent: (description: string | undefined) => string | undefined;
89
private _addContent;
910
private _updateContent;

src/manager/description/base/content_interface.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,33 @@ export abstract class ContentInterface {
2323
return `${this._id}-end -->`
2424
}
2525

26+
private getBlockIndices(description: string): { startIndex: number; contentStart: number; endIndex: number } | undefined {
27+
const startIndex = description.indexOf(this.startPattern);
28+
if (startIndex === -1) {
29+
return undefined;
30+
}
31+
32+
const contentStart = startIndex + this.startPattern.length;
33+
const endIndex = description.indexOf(this.endPattern, contentStart);
34+
if (endIndex === -1) {
35+
return undefined;
36+
}
37+
38+
return { startIndex, contentStart, endIndex };
39+
}
40+
2641
getContent = (description: string | undefined): string | undefined => {
2742
try {
2843
if (description === undefined) {
2944
return undefined;
3045
}
31-
const startIndex = description.indexOf(this.startPattern);
32-
if (startIndex === -1) {
33-
return undefined;
34-
}
35-
const contentStart = startIndex + this.startPattern.length;
36-
const endIndex = description.indexOf(this.endPattern, contentStart);
37-
if (endIndex === -1) {
46+
47+
const indices = this.getBlockIndices(description);
48+
if (!indices) {
3849
return undefined;
3950
}
4051

41-
return description.substring(contentStart, endIndex);
52+
return description.substring(indices.contentStart, indices.endIndex);
4253
} catch (error) {
4354
logError(`Error reading issue configuration: ${error}`);
4455
throw error;
@@ -55,21 +66,15 @@ export abstract class ContentInterface {
5566
}
5667

5768
private _updateContent = (description: string, content: string) => {
58-
const startIndex = description.indexOf(this.startPattern);
59-
if (startIndex === -1) {
60-
logError(`The content has a problem with open-close tags: ${this.startPattern} / ${this.endPattern}`);
61-
return undefined;
62-
}
63-
const contentStart = startIndex + this.startPattern.length;
64-
const endIndex = description.indexOf(this.endPattern, contentStart);
65-
if (endIndex === -1) {
69+
const indices = this.getBlockIndices(description);
70+
if (!indices) {
6671
logError(`The content has a problem with open-close tags: ${this.startPattern} / ${this.endPattern}`);
6772
return undefined;
6873
}
6974

70-
const start = description.substring(0, startIndex);
75+
const start = description.substring(0, indices.startIndex);
7176
const mid = `${this.startPattern}\n${content}\n${this.endPattern}`;
72-
const end = description.substring(endIndex + this.endPattern.length);
77+
const end = description.substring(indices.endIndex + this.endPattern.length);
7378

7479
return `${start}${mid}${end}`;
7580
}

0 commit comments

Comments
 (0)