Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
Renovate Bot
renovate
Commits
f730ff53
Unverified
Commit
f730ff53
authored
2 years ago
by
MaronHatoum
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix(platform/pr-body): refactor smartTruncate function (#14915)
Co-authored-by:
Rhys Arkins
<
rhys@arkins.net
>
parent
979de8d8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/modules/platform/utils/__snapshots__/pr-body.spec.ts.snap
+1
-3
1 addition, 3 deletions
...modules/platform/utils/__snapshots__/pr-body.spec.ts.snap
lib/modules/platform/utils/pr-body.ts
+23
-15
23 additions, 15 deletions
lib/modules/platform/utils/pr-body.ts
with
24 additions
and
18 deletions
lib/modules/platform/utils/__snapshots__/pr-body.spec.ts.snap
+
1
−
3
View file @
f730ff53
...
...
@@ -33,9 +33,7 @@ exports[`modules/platform/utils/pr-body .smartTruncate truncates to 1000 1`] = `
### [\`v19.47.0\`](https://togithub.com/renovatebot/renovate/releases/19.47.0)
##### Features
- **docker:** AWS ECR authentication support ([#​4497](htt
##### Feat
</details>
...
...
This diff is collapsed.
Click to expand it.
lib/modules/platform/utils/pr-body.ts
+
23
−
15
View file @
f730ff53
const
re
=
new
RegExp
(
`### Release Notes.*### Configuration`
,
'
ms
'
);
const
re
=
new
RegExp
(
`(?<preNotes>.*### Release Notes)(?<releaseNotes>.*)### Configuration(?<postNotes>.*)`
,
'
s
'
);
export
function
smartTruncate
(
input
:
string
,
len
:
number
):
string
{
if
(
input
.
length
<
len
)
{
return
input
;
}
const
releaseNotesMatch
=
re
.
exec
(
input
);
if
(
releaseNotesMatch
)
{
const
divider
=
`\n\n</details>\n\n---\n\n### Configuration`
;
const
[
releaseNotes
]
=
releaseNotesMatch
;
const
nonReleaseNotesLength
=
input
.
length
-
releaseNotes
.
length
-
divider
.
length
;
const
availableLength
=
len
-
nonReleaseNotesLength
;
if
(
availableLength
<=
0
)
{
return
input
.
substring
(
0
,
len
);
}
return
input
.
replace
(
releaseNotes
,
releaseNotes
.
slice
(
0
,
availableLength
)
+
divider
const
reMatch
=
re
.
exec
(
input
);
if
(
!
reMatch
)
{
return
input
.
substring
(
0
,
len
);
}
const
divider
=
`\n\n</details>\n\n---\n\n### Configuration`
;
const
preNotes
=
reMatch
.
groups
?.
preNotes
??
''
;
const
releaseNotes
=
reMatch
.
groups
?.
releaseNotes
??
''
;
const
postNotes
=
reMatch
.
groups
?.
postNotes
??
''
;
const
availableLength
=
len
-
(
preNotes
.
length
+
postNotes
.
length
+
divider
.
length
);
if
(
availableLength
<=
0
)
{
return
input
.
substring
(
0
,
len
);
}
else
{
return
(
preNotes
+
releaseNotes
.
slice
(
0
,
availableLength
)
+
divider
+
postNotes
);
}
return
input
.
substring
(
0
,
len
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment