Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
aports-qa-bot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
alpine
infra
aports-qa-bot
Commits
85691d25
Unverified
Commit
85691d25
authored
6 months ago
by
Pablo Correa Gómez
Committed by
Pablo Correa Gomez
6 months ago
Browse files
Options
Downloads
Patches
Plain Diff
feat(AutoMaintainer): support maintainer as variable
Fixes
#36
parent
1366f45c
No related branches found
No related tags found
1 merge request
!90
feat(AutoMaintainer): support maintainer as variable
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Services/AutoMaintainer/definition.go
+6
-5
6 additions, 5 deletions
Services/AutoMaintainer/definition.go
Services/AutoMaintainer/definition_test.go
+21
-0
21 additions, 0 deletions
Services/AutoMaintainer/definition_test.go
with
27 additions
and
5 deletions
Services/AutoMaintainer/definition.go
+
6
−
5
View file @
85691d25
...
...
@@ -58,7 +58,7 @@ func hasUser(gitlabClient *gitlab.Client, email string) (*gitlab.User, error) {
}
// ExtractMaintainer takes a ProjectID and a filename and tries to extract the user name
// and email address of the '# Maintainer:' field
// and email address of the '# Maintainer:' field
, or the 'maintainer=' variable
func
ExtractMaintainer
(
gitlabClient
*
gitlab
.
Client
,
projectID
interface
{},
filename
,
ref
string
)
(
*
[
2
]
Maintainer
,
error
)
{
maintainerSlice
:=
[
2
]
Maintainer
{}
...
...
@@ -72,15 +72,16 @@ func ExtractMaintainer(gitlabClient *gitlab.Client, projectID interface{}, filen
}
// Run over every line of the received raw file, we will check the first
// occurrence of '# Maintainer'
// occurrence of '# Maintainer'
or 'maintainer='
scanner
:=
bufio
.
NewScanner
(
bytes
.
NewReader
(
file
))
for
scanner
.
Scan
()
{
scannedLine
:=
scanner
.
Text
()
if
strings
.
HasPrefix
(
scannedLine
,
"# Maintainer:"
)
{
// Strip the # Maintainer: and pass everything else
line
:
=
strings
.
ReplaceAll
(
scannedL
ine
,
"# Maintainer:"
,
""
)
if
strings
.
HasPrefix
(
scannedLine
,
"maintainer="
)
||
strings
.
HasPrefix
(
scannedLine
,
"# Maintainer:"
)
{
line
:=
strings
.
TrimPrefix
(
scannedLine
,
"maintainer="
)
line
=
strings
.
TrimPrefix
(
l
ine
,
"# Maintainer:"
)
line
=
strings
.
TrimSpace
(
line
)
line
=
strings
.
Trim
(
line
,
"
\"
"
)
address
,
err
:=
mail
.
ParseAddress
(
line
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
Services/AutoMaintainer/definition_test.go
+
21
−
0
View file @
85691d25
...
...
@@ -91,6 +91,27 @@ func Test_ExtractMaintainerSimple(t *testing.T) {
assertEqStr
(
t
,
"Foo"
,
maintainerSlice
[
1
]
.
GetName
())
}
func
Test_ExtractMaintainerVar
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
mocklab
.
Setup
(
t
)
defer
mocklab
.
Teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/projects/1/repository/files/APKBUILD/raw"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
_
,
err
:=
io
.
WriteString
(
w
,
"maintainer=
\"
Foo <foo@bar.org>
\"
"
);
err
!=
nil
{
t
.
Fatalf
(
"error writing response: %v"
,
err
)
}
})
maintainerSlice
,
err
:=
ExtractMaintainer
(
client
,
1
,
"APKBUILD"
,
"master"
)
if
err
!=
nil
{
t
.
Errorf
(
"got unexpected error: %v"
,
err
)
return
}
assertEqStr
(
t
,
"foo@bar.org"
,
maintainerSlice
[
0
]
.
GetEmail
())
assertEqStr
(
t
,
"Foo"
,
maintainerSlice
[
0
]
.
GetName
())
assertEqStr
(
t
,
"foo@bar.org"
,
maintainerSlice
[
1
]
.
GetEmail
())
assertEqStr
(
t
,
"Foo"
,
maintainerSlice
[
1
]
.
GetName
())
}
func
Test_ExtractMaintainerTeam
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
mocklab
.
Setup
(
t
)
defer
mocklab
.
Teardown
(
server
)
...
...
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