Open4

Argo CD Notifications x Slackでプルリクエストのリンクを一緒に通知したい

omihirofumiomihirofumi

Slack通知に、関連するプルリクエストのリンクと一緒に通知したい

omihirofumiomihirofumi

コミットメッセージをtemplate側で取得できるぽいので、コメントを使ってやるパターンで実装してみる。
(コミットメッセージが変わると使えなくなるけど)
https://argo-cd.readthedocs.io/en/stable/operator-manual/notifications/triggers/#repo

repo.GetCommitMetadata(sha string) CommitMetadata
Returns commit metadata. The commit must belong to the application source repository. CommitMetadata fields:

  • Message string commit message
  • Author string- commit author
  • Date time.Time - commit creation date
  • Tags []string - Associated tags
omihirofumiomihirofumi

デフォルトのマージコミットのメッセージを想定するとこんな感じ
Merge pull request #{PR number} from xxxxxx

  template.app-sync-succeeded: |
    message: |
      {{ $commitMessage := (call .repo.GetCommitMetadata .app.status.sync.revision).Message }}
      {{ $prText := regexFind "#[0-9]+" $commitMessage }}
      {{ if $prText }}https://github.com/omihirofumi/xxxxxx/pull/{{ trimPrefix "#" $prText }}{{ end }}