Skip to content

Commit 82afa87

Browse files
feat: Update script to only add label to pre-release issues
1 parent 50b9468 commit 82afa87

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

dist/index.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8929,17 +8929,25 @@ const versionLabel = "Version: ";
89298929
const versionTitlesInMarkdown = ["Version", "New Version"];
89308930
const rnInfoTitleInMarkdown = "Output of `react-native info`";
89318931
const labelForNoVersion = "Version: unspecified";
8932+
function isTokenWithText(token) {
8933+
return !!(token === null || token === void 0 ? void 0 : token.text);
8934+
}
89328935
const getVersionFromIssueBody = (issueBody) => {
89338936
let versionFromIssueBody = "";
89348937
// Parse the markdown from the issue body
89358938
const markdownSection = marked_1.marked.lexer(issueBody);
89368939
// Loop through all sections
89378940
for (const markdownSectionIndex in markdownSection) {
8941+
// Skip sections that don't contain text
8942+
const currentSection = markdownSection[markdownSectionIndex];
8943+
if (!isTokenWithText(currentSection)) {
8944+
continue;
8945+
}
89388946
// If this section matches `versionTitleInMarkdown`
8939-
if (versionTitlesInMarkdown.includes(markdownSection[markdownSectionIndex].text)) {
8947+
if (versionTitlesInMarkdown.includes(currentSection.text)) {
89408948
// Then the version can be found in the next section
89418949
const specifiedVersion = markdownSection[Number(markdownSectionIndex) + 1];
8942-
if (!specifiedVersion.text) {
8950+
if (!isTokenWithText(specifiedVersion)) {
89438951
continue;
89448952
}
89458953
const parsedVersion = (0, parse_1.default)(specifiedVersion.text);
@@ -8950,11 +8958,10 @@ const getVersionFromIssueBody = (issueBody) => {
89508958
break;
89518959
}
89528960
// If this section matches `rnInfoTitleInMarkdown`
8953-
if (markdownSection[markdownSectionIndex].text ===
8954-
rnInfoTitleInMarkdown) {
8961+
if (currentSection.text === rnInfoTitleInMarkdown) {
89558962
// Then the version can be found in the next section
89568963
const rnInfoOutput = markdownSection[Number(markdownSectionIndex) + 1];
8957-
if (!rnInfoOutput.text) {
8964+
if (!isTokenWithText(rnInfoOutput)) {
89588965
continue;
89598966
}
89608967
const rnInfoRNPart = rnInfoOutput.text.match(/react-native:(.+?)=>/);
@@ -9001,6 +9008,10 @@ const init = () => __awaiter(void 0, void 0, void 0, function* () {
90019008
repo: issue.repo,
90029009
issue_number: issue.number,
90039010
});
9011+
if (labels.every(({ name }) => name !== "pre-release")) {
9012+
core.debug("Issue not tagged with pre-release");
9013+
return;
9014+
}
90049015
// Loop through all labels and remove the version label if it exists
90059016
// and is not the same as the version from the issue body
90069017
try {

src/index.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ const versionTitlesInMarkdown = ["Version", "New Version"];
88
const rnInfoTitleInMarkdown = "Output of `react-native info`";
99
const labelForNoVersion = "Version: unspecified";
1010

11+
type TokenWithText = {
12+
text: string;
13+
};
14+
15+
function isTokenWithText(token: any): token is TokenWithText {
16+
return !!token?.text;
17+
}
18+
1119
const getVersionFromIssueBody = (issueBody: string) => {
1220
let versionFromIssueBody = "";
1321

@@ -16,17 +24,19 @@ const getVersionFromIssueBody = (issueBody: string) => {
1624

1725
// Loop through all sections
1826
for (const markdownSectionIndex in markdownSection) {
27+
// Skip sections that don't contain text
28+
const currentSection = markdownSection[markdownSectionIndex];
29+
if (!isTokenWithText(currentSection)) {
30+
continue;
31+
}
32+
1933
// If this section matches `versionTitleInMarkdown`
20-
if (
21-
versionTitlesInMarkdown.includes(
22-
(markdownSection[markdownSectionIndex] as any).text
23-
)
24-
) {
34+
if (versionTitlesInMarkdown.includes(currentSection.text)) {
2535
// Then the version can be found in the next section
26-
const specifiedVersion: any =
36+
const specifiedVersion =
2737
markdownSection[Number(markdownSectionIndex) + 1];
2838

29-
if (!specifiedVersion.text) {
39+
if (!isTokenWithText(specifiedVersion)) {
3040
continue;
3141
}
3242

@@ -42,15 +52,11 @@ const getVersionFromIssueBody = (issueBody: string) => {
4252
}
4353

4454
// If this section matches `rnInfoTitleInMarkdown`
45-
if (
46-
(markdownSection[markdownSectionIndex] as any).text ===
47-
rnInfoTitleInMarkdown
48-
) {
55+
if (currentSection.text === rnInfoTitleInMarkdown) {
4956
// Then the version can be found in the next section
50-
const rnInfoOutput: any =
51-
markdownSection[Number(markdownSectionIndex) + 1];
57+
const rnInfoOutput = markdownSection[Number(markdownSectionIndex) + 1];
5258

53-
if (!rnInfoOutput.text) {
59+
if (!isTokenWithText(rnInfoOutput)) {
5460
continue;
5561
}
5662

@@ -117,6 +123,12 @@ const init = async () => {
117123
issue_number: issue.number,
118124
});
119125

126+
if (labels.every(({ name }) => name !== "pre-release")) {
127+
core.debug("Issue not tagged with pre-release");
128+
129+
return;
130+
}
131+
120132
// Loop through all labels and remove the version label if it exists
121133
// and is not the same as the version from the issue body
122134
try {

0 commit comments

Comments
 (0)