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
50191def
Unverified
Commit
50191def
authored
8 months ago
by
Jamie Tanna
Committed by
GitHub
8 months ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor(gomod): rename `depName` (#30030)
Co-authored-by:
Rhys Arkins
<
rhys@arkins.net
>
parent
69495a1c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/manager/gomod/update.ts
+20
-16
20 additions, 16 deletions
lib/modules/manager/gomod/update.ts
with
20 additions
and
16 deletions
lib/modules/manager/gomod/update.ts
+
20
−
16
View file @
50191def
...
...
@@ -3,12 +3,12 @@ import { logger } from '../../../logger';
import
{
newlineRegex
,
regEx
}
from
'
../../../util/regex
'
;
import
type
{
UpdateDependencyConfig
}
from
'
../types
'
;
function
get
Dep
NameWithNoVersion
(
depN
ame
:
string
):
string
{
let
depN
ameNoVersion
=
depN
ame
.
split
(
'
/
'
).
slice
(
0
,
3
).
join
(
'
/
'
);
if
(
depN
ameNoVersion
.
startsWith
(
'
gopkg.in
'
))
{
depN
ameNoVersion
=
depN
ameNoVersion
.
replace
(
regEx
(
/
\.
v
\d
+$/
),
''
);
function
getNameWithNoVersion
(
n
ame
:
string
):
string
{
let
n
ameNoVersion
=
n
ame
.
split
(
'
/
'
).
slice
(
0
,
3
).
join
(
'
/
'
);
if
(
n
ameNoVersion
.
startsWith
(
'
gopkg.in
'
))
{
n
ameNoVersion
=
n
ameNoVersion
.
replace
(
regEx
(
/
\.
v
\d
+$/
),
''
);
}
return
depN
ameNoVersion
;
return
n
ameNoVersion
;
}
export
function
updateDependency
({
...
...
@@ -17,16 +17,17 @@ export function updateDependency({
}:
UpdateDependencyConfig
):
string
|
null
{
try
{
logger
.
debug
(
`gomod.updateDependency:
${
upgrade
.
newValue
}
`
);
const
{
depName
,
depType
,
updateType
}
=
upgrade
;
const
{
depType
,
updateType
}
=
upgrade
;
const
currentName
=
upgrade
.
depName
;
if
(
updateType
===
'
replacement
'
)
{
logger
.
warn
(
'
gomod manager does not support replacement updates yet
'
);
return
null
;
}
// istanbul ignore if: should never happen
if
(
!
dep
Name
||
!
upgrade
.
managerData
)
{
if
(
!
current
Name
||
!
upgrade
.
managerData
)
{
return
null
;
}
const
dep
NameNoVersion
=
get
Dep
NameWithNoVersion
(
dep
Name
);
const
current
NameNoVersion
=
getNameWithNoVersion
(
current
Name
);
const
lines
=
fileContent
.
split
(
newlineRegex
);
// istanbul ignore if: hard to test
if
(
lines
.
length
<=
upgrade
.
managerData
.
lineNumber
)
{
...
...
@@ -36,11 +37,11 @@ export function updateDependency({
const
lineToChange
=
lines
[
upgrade
.
managerData
.
lineNumber
];
logger
.
trace
({
upgrade
,
lineToChange
},
'
go.mod current line
'
);
if
(
!
lineToChange
.
includes
(
dep
NameNoVersion
)
&&
!
lineToChange
.
includes
(
current
NameNoVersion
)
&&
!
lineToChange
.
includes
(
'
rethinkdb/rethinkdb-go.v5
'
)
)
{
logger
.
debug
(
{
lineToChange
,
depName
},
{
lineToChange
,
depName
:
currentName
},
"
go.mod current line doesn't contain dependency
"
,
);
return
null
;
...
...
@@ -85,7 +86,7 @@ export function updateDependency({
return
fileContent
;
}
logger
.
debug
(
{
depName
,
lineToChange
,
newDigestRightSized
},
{
depName
:
currentName
,
lineToChange
,
newDigestRightSized
},
'
gomod: need to update digest
'
,
);
newLine
=
lineToChange
.
replace
(
...
...
@@ -101,9 +102,9 @@ export function updateDependency({
);
}
if
(
upgrade
.
updateType
===
'
major
'
)
{
logger
.
debug
(
`gomod: major update for
${
dep
Name
}
`
);
if
(
dep
Name
.
startsWith
(
'
gopkg.in/
'
))
{
const
oldV
=
dep
Name
.
split
(
'
.
'
).
pop
();
logger
.
debug
(
`gomod: major update for
${
current
Name
}
`
);
if
(
current
Name
.
startsWith
(
'
gopkg.in/
'
))
{
const
oldV
=
current
Name
.
split
(
'
.
'
).
pop
();
newLine
=
newLine
.
replace
(
`.
${
oldV
}
`
,
`.v
${
upgrade
.
newMajor
}
`
);
// Package renames - I couldn't think of a better place to do this
newLine
=
newLine
.
replace
(
...
...
@@ -115,9 +116,12 @@ export function updateDependency({
!
newLine
.
includes
(
`/v
${
upgrade
.
newMajor
}
`
)
&&
!
upgrade
.
newValue
!
.
endsWith
(
'
+incompatible
'
)
)
{
if
(
dep
Name
===
dep
NameNoVersion
)
{
if
(
current
Name
===
current
NameNoVersion
)
{
// If package currently has no version, pin to latest one.
newLine
=
newLine
.
replace
(
depName
,
`
${
depName
}
/v
${
upgrade
.
newMajor
}
`
);
newLine
=
newLine
.
replace
(
currentName
,
`
${
currentName
}
/v
${
upgrade
.
newMajor
}
`
,
);
}
else
{
// Replace version
const
[
oldV
]
=
upgrade
.
currentValue
!
.
split
(
'
.
'
);
...
...
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