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
Reimplement translation prs #143
Conversation
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.
LGTM, very minimal comments though.
server/enterprise.go
Outdated
@@ -14,7 +14,7 @@ import ( | |||
) | |||
|
|||
func (s *Server) triggerEETestsForOrgMembers(pr *model.PullRequest) { | |||
if s.IsOrgMember(pr.Username) { | |||
if s.IsOrgMember(pr.Username) || s.IsKnownUser(pr.Username) { |
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.
Is this needed? I mean do we want to run enterprise tests for external known users?
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 renamed it to IsTrustedUser(). I am for adding this, because the translation bot only modifies translation files and otherwise I have to add the EETests label and then check in again in an hour. But if you have objections, I am fine with not whitelisting the CLAExcluded bots. mattermost/mattermost#14872
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.
No, I'm fine and there's no harm running EE tests anyway.
|
||
dataMsg := fmt.Sprintf("####[%v translations PR %v](%v)\n", pr.RepoName, time.Now().UTC().Format(time.RFC3339), pr.URL) | ||
msg := dataMsg + s.Config.TranslationsMattermostMessage | ||
mlog.Debug("Sending Mattermost message", mlog.String("message", msg)) |
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'd suggest changing the message to something like Translation
instead of Mattermost for clarity.
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 does it make it clearer?
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.
Because the payload is being sent to translation service and not Mattermost. Isn't it?
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.
It is sent to mattermost. It contains the links to the PRs for translations: https://community.mattermost.com/core/pl/sqzth7ryibgrbqj196trrs4hec
|
||
webhookRequest := &Payload{Username: "Weblate", Text: msg} | ||
if err := s.sendToWebhook(s.Config.TranslationsMattermostWebhookURL, webhookRequest); err != nil { | ||
mlog.Error("Unable to post to Mattermost webhook", mlog.Err(err)) |
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.
The same, so if any error happens and one looks at the logs won't get confused.
server/webhook.go
Outdated
func (s *Server) sendToWebhook(payload *Payload) error { | ||
func (s *Server) sendToWebhook(webhookURL string, payload *Payload) error { | ||
if webhookURL == "" { | ||
err := errors.New("no Mattermost webhook URL set: unable to send message") |
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.
The same, may be drop Mattermost
?
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.
Pushing it out of my queue until some tests are added as discussed offline. Please re-request review when the tests are added. Thanks.
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 also want to understand how does this change know that this is a translation PR? From what I understand, it is unconditionally posting the message to the webhook URL for every PR.
Perhaps I have missed something that I am not aware of?
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.
Getting there. But needs some more work. Please take a look at my comments. Thanks!
server/utils.go
Outdated
} | ||
defer r.Body.Close() |
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 am not seeing this resolved. Please see my comment #143. We can just use closeBody
here.
server/webhook.go
Outdated
badRequestR := &http.Response{ | ||
StatusCode: http.StatusBadRequest, | ||
Body: ioutil.NopCloser(bytes.NewBufferString(err.Error())), | ||
} |
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.
This does not appear to be resolved?
server/webhook.go
Outdated
type WebhookValidationError struct { | ||
err string | ||
} | ||
|
||
func (e *WebhookValidationError) Error() string { | ||
return fmt.Sprintf("%v", e.err) | ||
} | ||
|
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.
This implements only partially what I suggested. This just wraps the error with a type, and does not do anything else. As it is, it's not very useful. I was suggesting that a field added to the struct which will indicate what is not set- url/username/text.
Please also add godocs to both the struct and the method.
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.
Can you please send me an example for what you mean by this?
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.
Sure.
// WebhookValidationError contains an error in the webhook payload.
type WebhookValidationError struct {
field string
}
// Error implements the error interface.
func (e *WebhookValidationError) Error() string {
return "invalid" + e.field
}
func newWebhookValidationError(field string) *WebhookValidationError {
return &WebhookValidationError{
field: field,
}
}
// from code
if webhookURL == "" {
return newWebhookValidationError("webhook URL")
}
// in test
var whError *WebhookValidationError
require.True(errors.As(err, &whError))
assert.Equal(whError.field, "webhook URL")
Let me know if that helps. (Code is untested, I just wrote here directly)
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.
This helps immensely! Thank you so much!
server/cla.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
r, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
mlog.Error("Unable to get CLA list", mlog.Err(err)) |
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.
Unrelated to this PR, but this is an anti-pattern. Logging and then returning the same error. We need to do a sweep to fix all of these.
server/webhook_test.go
Outdated
if testing.Short() { | ||
t.Skip("skipping integration test") | ||
} |
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.
Any reason for this?
Same for below.
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 want to differentiate between running unit tests and implementation tests. I looked up on how to accomplish this. This was, what came up as a go to solution.
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 this is an unit test from what I understand. There is no external dependency with any other service. It's purely inside the code.
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.
OK, removed.
server/webhook_test.go
Outdated
} | ||
|
||
s := &Server{ | ||
StartTime: time.Now(), |
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 this in the test?
Same for below.
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.
We are calling s.sendToWebhook(context.Background(), mattermost.URL, validPayload)
. Is there another way?
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.
Sorry, I meant the StartTime
field. Is that needed?
…attermost-mattermod into reimplement-translation-prs
…attermost-mattermod into reimplement-translation-prs
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.
Apart from the payload validation, just some tiny things remaining.
Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
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.
Thanks for your patience with this @metanerd. Looks great now.
Thanks to you, sir! |
Summary
Before the migration from pootle to weblate, we got translation PRs for review into the i18n channel. This PR implements the same logic for weblate.Ticket Link