-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: event selection more specific - RK-19082 #76
Conversation
Signed-off-by: Gosha <gosha@rookout.com>
Signed-off-by: Gosha <gosha@rookout.com>
Signed-off-by: Gosha <gosha@rookout.com>
Github Enforcer opened Task: RK-19082 |
Signed-off-by: Gosha <gosha@rookout.com>
Signed-off-by: Gosha <gosha@rookout.com>
Signed-off-by: Gosha <gosha@rookout.com>
Signed-off-by: Gosha <gosha@rookout.com>
func (m *MockGitProvider) GetFiles(ctx *context.Context, repo string, branch string, paths []string) ([]*git_provider.CommitFile, error) { | ||
var commitFiles []*git_provider.CommitFile | ||
|
||
switch repo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use a map instead of this nested switch cases.
the map key will be repo+branch+path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done !
Signed-off-by: Gosha <gosha@rookout.com>
Signed-off-by: Gosha <gosha@rookout.com>
Signed-off-by: Gosha <gosha@rookout.com>
Signed-off-by: Gosha <gosha@rookout.com>
Signed-off-by: Gosha <gosha@rookout.com>
type MockGitProvider struct{} | ||
|
||
func GetContent(filename string) *string { | ||
switch filename { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use map also here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
func (m *MockGitProvider) GetFile(ctx *context.Context, repo string, branch string, path string) (*git_provider.CommitFile, error) { | ||
fileMappings := *GetFileMap() | ||
if branchMap, ok := fileMappings[repo]; ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can flatten the map so you will only have to check single key that is "repo/branch/path"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
func GetFileMap() *map[string]map[string]map[string]git_provider.CommitFile { | ||
return &map[string]map[string]map[string]git_provider.CommitFile{ | ||
"repo1": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flatten it
return &map[string]git_provider.CommitFile{
"repo1/branch1/.workflows/main.yaml": git_provider.CommitFile{
Path: utils.SPtr(".workflows/main.yaml"),
Content: GetContent(".workflows/main.yaml"),
},
"repo1/branch1/.workflows/exit.yaml": git_provider.CommitFile{
Path: utils.SPtr(".workflows/exit.yaml"),
Content: GetContent(".workflows/exit.yaml"),
},
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qadiludmer not sure that it's better, is much easier to read and add new repos, branches and files in structured map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the access is less pretty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, but I have the GetFile and GetFiles function for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments
Signed-off-by: Gosha <gosha@rookout.com>
Signed-off-by: Gosha <gosha@rookout.com>
Signed-off-by: Gosha <gosha@rookout.com>
Signed-off-by: Gosha <gosha@rookout.com>
return fileContentMap[filename] | ||
} | ||
|
||
func GetFileMap() *map[string]*git_provider.CommitFile { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need a function for retuning a const ? can't we put the map in a global var ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hate globals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also it can be reused in other places too, if needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function contains a logic - you don't have any logic here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes... after reading a little, moving it to global
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var fileContentMap := map[string]*string{
"main.yaml": utils.SPtr("main.yaml"),
"exit.yaml": utils.SPtr("exit.yaml"),
"parameters.yaml": utils.SPtr("parameters.yaml"),
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and then
var commitFileMap := map[string]*git_provider.CommitFile{
"repo1/branch1/.workflows/main.yaml": &git_provider.CommitFile{
Path: utils.SPtr(".workflows/main.yaml"),
Content: fileContentMap["main.yaml"],
},
....
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
almost. see my second comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did it, and renamed it
"parameters.yaml": utils.SPtr("parameters.yaml"), | ||
} | ||
|
||
func GetContent(filename string) *string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need this function ? all it does is accessing a map so the caller can do it too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment
Signed-off-by: Gosha <gosha@rookout.com>
Signed-off-by: Gosha <gosha@rookout.com>
Signed-off-by: Gosha gosha@rookout.com
Pull Request
Description
Please provide a brief description of the changes made in this pull request.
Related Issue(s)
If this pull request addresses or relates to any open issues, please mention them here using the syntax
Fixes #<issue_number>
orResolves #<issue_number>
.Checklist
Before submitting this pull request, please ensure that you have completed the following tasks:
Testing Instructions
Please provide clear instructions on how to test and verify the changes made in this pull request.
Additional Information
Add any additional information or context that would be helpful in understanding and reviewing this pull request.