Skip to content

Commit

Permalink
debug logging subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mickmister committed Oct 3, 2023
1 parent 6109662 commit 7c36f8e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions server/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,30 +125,43 @@ func (p *Plugin) getUserID() string {
}

func (p *Plugin) matchesSubsciptionFilters(wh *webhook, filters SubscriptionFilters) bool {
requestId := model.NewId()

Check failure on line 128 in server/subscribe.go

View workflow job for this annotation

GitHub Actions / plugin-ci / lint

ST1003: var requestId should be requestID (stylecheck)
log := func(msg interface{}) {
p.client.Log.Debug("matchesSubsciptionFilters DEBUG LOG", "issue_id", wh.Issue.ID, "request_id", requestId, "msg", msg)
}

log(1)

webhookEvents := wh.Events()
foundEvent := false
eventTypes := filters.Events
if eventTypes.Intersection(webhookEvents).Len() > 0 {
log(2)
foundEvent = true
} else if eventTypes.ContainsAny(eventUpdatedAny) {
log(3)
for _, eventType := range webhookEvents.Elems() {
if strings.HasPrefix(eventType, "event_updated") || strings.HasSuffix(eventType, "comment") {
log(4)
foundEvent = true
}
}
}

if !foundEvent {
log(5)
return false
}

issue := &wh.JiraWebhook.Issue

if filters.IssueTypes.Len() != 0 && !filters.IssueTypes.ContainsAny(issue.Fields.Type.ID) {
log(6)
return false
}

if filters.Projects.Len() != 0 && !filters.Projects.ContainsAny(issue.Fields.Project.Key) {
log(7)
return false
}

Expand All @@ -159,29 +172,39 @@ func (p *Plugin) matchesSubsciptionFilters(wh *webhook, filters SubscriptionFilt

// Broken filter, values must be provided
if inclusion == "" || (field.Values.Len() == 0 && inclusion != FilterEmpty) {
log(8)
return false
}

if field.Key == securityLevelField {
containsSecurityLevelFilter = true
log(9)

if inclusion == FilterExcludeAny && useEmptySecurityLevel {
log(10)
inclusion = FilterEmpty
}
}

value := getIssueFieldValue(issue, field.Key)
if !isValidFieldInclusion(field, value, inclusion) {
log(11)
log(fmt.Sprintf("field %s value %s inclusion %s", field.Key, value.Elems(), inclusion))
return false
}
}

if !containsSecurityLevelFilter && useEmptySecurityLevel {
securityLevel := getIssueFieldValue(issue, securityLevelField)
log(12)
if securityLevel.Len() > 0 {
log(13)
return false
}
}

log(14)

return true
}

Expand Down

0 comments on commit 7c36f8e

Please sign in to comment.