prow/commentpruner/commentpruner.go
func (c *EventClient) PruneComments(shouldPrune func(github.IssueComment) bool) {
	c.once.Do(func() {
		botName, err := c.ghc.BotName()
		if err != nil {
			c.log.WithError(err).Error("failed to get the bot's name. Pruning will consider all comments.")
		}
		comments, err := c.ghc.ListIssueComments(c.org, c.repo, c.number)
		if err != nil {
			c.log.WithError(err).Errorf("failed to list comments for %s/%s#%d", c.org, c.repo, c.number)
		}
		if botName != "" {
			for _, comment := range comments {
				if comment.User.Login == botName {
					c.comments = append(c.comments, comment)
				}
			}
		}
	})

	c.lock.Lock()
	defer c.lock.Unlock()

	var remaining []github.IssueComment
	for _, comment := range c.comments {
		removed := false
		if shouldPrune(comment) {
			if err := c.ghc.DeleteComment(c.org, c.repo, comment.ID); err != nil {
				c.log.WithError(err).Errorf("failed to delete stale comment with ID '%d'", comment.ID)
			} else {
				removed = true
			}
		}
		if !removed {
			remaining = append(remaining, comment)
		}
	}
	c.comments = remaining
}
func (c *EventClient) PruneComments(shouldPrune func(github.IssueComment) bool) {
	c.once.Do(func() {
		botName, err := c.ghc.BotName()
		if err != nil {
			c.log.WithError(err).Error("failed to get the bot's name. Pruning will consider all comments.")
		}
		comments, err := c.ghc.ListIssueComments(c.org, c.repo, c.number)
		if err != nil {
			c.log.WithError(err).Errorf("failed to list comments for %s/%s#%d", c.org, c.repo, c.number)
		}
		if botName != "" {
			for _, comment := range comments {
				if comment.User.Login == botName {
					c.comments = append(c.comments, comment)
				}
			}
		}
	})

	c.lock.Lock()
	defer c.lock.Unlock()

	var remaining []github.IssueComment
	for _, comment := range c.comments {
		removed := false
		if shouldPrune(comment) {
			if err := c.ghc.DeleteComment(c.org, c.repo, comment.ID); err != nil {
				c.log.WithError(err).Errorf("failed to delete stale comment with ID '%d'", comment.ID)
			} else {
				removed = true
			}
		}
		if !removed {
			remaining = append(remaining, comment)
		}
	}
	c.comments = remaining
}
func ( c * EventClient ) PruneComments ( shouldPrune func ( github . IssueComment ) bool ) { c . once . Do ( func ( ) { botName , err := c . ghc . BotName ( ) if err != nil { c . log . WithError ( err ) . Error ( " " ) } comments , err := c . ghc . ListIssueComments ( c . org , c . repo , c . number ) if err != nil { c . log . WithError ( err ) . Errorf ( " " , c . org , c . repo , c . number ) } if botName != " " { for _ , comment := range comments { if comment . User . Login == botName { c . comments = append ( c . comments , comment ) } } } } ) c . lock . Lock ( ) defer c . lock . Unlock ( ) var remaining [ ] github . IssueComment for _ , comment := range c . comments { removed := false if shouldPrune ( comment ) { if err := c . ghc . DeleteComment ( c . org , c . repo , comment . ID ) ; err != nil { c . log . WithError ( err ) . Errorf ( " " , comment . ID ) } else { removed = true } } if ! removed { remaining = append ( remaining , comment ) } } c . comments = remaining }
// PruneComments fetches issue comments if they have not yet been fetched for this webhook event
// and then deletes any bot comments indicated by the func 'shouldPrune'.
PruneComments fetches issue comments if they have not yet been fetched for this webhook event and then deletes any bot comments indicated by the func shouldPrune .