Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
files-updater-npm
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
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
go-semantic-release
files-updater-npm
Commits
6b2c0b57
Commit
6b2c0b57
authored
2 years ago
by
Christoph Witzko
Browse files
Options
Downloads
Patches
Plain Diff
style: add .golangci-lint.yaml
parent
f3056f6f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.golangci.yaml
+25
-0
25 additions, 0 deletions
.golangci.yaml
pkg/updater/npm.go
+5
-7
5 additions, 7 deletions
pkg/updater/npm.go
pkg/updater/npm_test.go
+9
-10
9 additions, 10 deletions
pkg/updater/npm_test.go
with
39 additions
and
17 deletions
.golangci.yaml
0 → 100644
+
25
−
0
View file @
6b2c0b57
linters
:
enable
:
-
errorlint
-
forbidigo
-
gochecknoinits
-
gocritic
-
goconst
-
gocyclo
-
gofumpt
-
goimports
-
misspell
-
revive
-
unconvert
-
unparam
-
wastedassign
linters-settings
:
gocyclo
:
min-complexity
:
12
gofumpt
:
extra-rules
:
true
govet
:
enable-all
:
true
disable
:
-
fieldalignment
This diff is collapsed.
Click to expand it.
pkg/updater/npm.go
+
5
−
7
View file @
6b2c0b57
...
...
@@ -2,7 +2,6 @@ package updater
import
(
"encoding/json"
"io/ioutil"
"os"
"path"
)
...
...
@@ -11,8 +10,7 @@ const npmrc = "//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n"
var
FUVERSION
=
"dev"
type
Updater
struct
{
}
type
Updater
struct
{}
func
(
u
*
Updater
)
Init
(
m
map
[
string
]
string
)
error
{
return
nil
...
...
@@ -30,7 +28,7 @@ func (u *Updater) ForFiles() string {
return
"package
\\
.json"
}
func
updateJ
son
File
(
fName
,
newVersion
string
)
error
{
func
updateJ
SON
File
(
fName
,
newVersion
string
)
error
{
file
,
err
:=
os
.
OpenFile
(
fName
,
os
.
O_RDWR
,
0
)
if
err
!=
nil
{
return
err
...
...
@@ -56,13 +54,13 @@ func updateJsonFile(fName, newVersion string) error {
}
func
(
u
*
Updater
)
Apply
(
file
,
newVersion
string
)
error
{
if
err
:=
updateJ
son
File
(
file
,
newVersion
);
err
!=
nil
{
if
err
:=
updateJ
SON
File
(
file
,
newVersion
);
err
!=
nil
{
return
err
}
packageLockPath
:=
path
.
Join
(
path
.
Dir
(
file
),
"package-lock.json"
)
if
_
,
err
:=
os
.
Stat
(
packageLockPath
);
err
==
nil
{
if
err
:=
updateJ
son
File
(
packageLockPath
,
newVersion
);
err
!=
nil
{
if
err
:=
updateJ
SON
File
(
packageLockPath
,
newVersion
);
err
!=
nil
{
return
err
}
}
...
...
@@ -74,7 +72,7 @@ func (u *Updater) Apply(file, newVersion string) error {
var
err
error
npmrcPath
:=
path
.
Join
(
path
.
Dir
(
file
),
".npmrc"
)
if
_
,
err
=
os
.
Stat
(
npmrcPath
);
os
.
IsNotExist
(
err
)
{
return
ioutil
.
WriteFile
(
npmrcPath
,
[]
byte
(
npmrc
),
0644
)
return
os
.
WriteFile
(
npmrcPath
,
[]
byte
(
npmrc
),
0
o
644
)
}
return
err
...
...
This diff is collapsed.
Click to expand it.
pkg/updater/npm_test.go
+
9
−
10
View file @
6b2c0b57
...
...
@@ -2,7 +2,6 @@ package updater
import
(
"encoding/json"
"io/ioutil"
"os"
"testing"
...
...
@@ -17,15 +16,15 @@ func TestNpmUpdater(t *testing.T) {
nVer
:=
"1.2.3"
nVerJSON
:=
json
.
RawMessage
(
"
\"
"
+
nVer
+
"
\"
"
)
npmrcPath
:=
"../../test/.npmrc"
pkgJ
son
Path
:=
"../../test/package.json"
pkgJ
SON
Path
:=
"../../test/package.json"
os
.
Remove
(
npmrcPath
)
err
:=
updater
.
Apply
(
pkgJ
son
Path
,
nVer
)
err
:=
updater
.
Apply
(
pkgJ
SON
Path
,
nVer
)
require
.
NoError
(
err
)
npmfile
,
err
:=
ioutil
.
ReadFile
(
npmrcPath
)
npmfile
,
err
:=
os
.
ReadFile
(
npmrcPath
)
require
.
NoError
(
err
)
require
.
Equal
([]
byte
(
npmrc
),
npmfile
,
"invalid .npmrc"
)
f
,
err
:=
os
.
OpenFile
(
pkgJ
son
Path
,
os
.
O_RDONLY
,
0
)
f
,
err
:=
os
.
OpenFile
(
pkgJ
SON
Path
,
os
.
O_RDONLY
,
0
)
require
.
NoError
(
err
)
defer
f
.
Close
()
var
data
map
[
string
]
json
.
RawMessage
...
...
@@ -47,18 +46,18 @@ func TestNpmrc(t *testing.T) {
nVer
:=
"1.2.3"
npmrcPath
:=
"../../test/.npmrc"
pkgJ
son
Path
:=
"../../test/package.json"
pkgJ
SON
Path
:=
"../../test/package.json"
err
:=
ioutil
.
WriteFile
(
npmrcPath
,
[]
byte
(
"TEST"
),
0644
)
err
:=
os
.
WriteFile
(
npmrcPath
,
[]
byte
(
"TEST"
),
0
o
644
)
require
.
NoError
(
err
)
updater
:=
&
Updater
{}
err
=
updater
.
Apply
(
pkgJ
son
Path
,
nVer
)
err
=
updater
.
Apply
(
pkgJ
SON
Path
,
nVer
)
require
.
NoError
(
err
)
npmfile
,
err
:=
ioutil
.
ReadFile
(
npmrcPath
)
npmfile
,
err
:=
os
.
ReadFile
(
npmrcPath
)
require
.
NoError
(
err
)
require
.
Equal
([]
byte
(
"TEST"
),
npmfile
,
"invalid .npmrc"
)
f
,
err
:=
os
.
OpenFile
(
pkgJ
son
Path
,
os
.
O_RDONLY
,
0
)
f
,
err
:=
os
.
OpenFile
(
pkgJ
SON
Path
,
os
.
O_RDONLY
,
0
)
require
.
NoError
(
err
)
defer
f
.
Close
()
require
.
NoError
(
err
)
...
...
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