| 173 | } |
| 174 | |
| 175 | func WithEntityJobFilter(ghEntity params.ForgeEntity) dbCommon.PayloadFilterFunc { |
| 176 | return func(payload dbCommon.ChangePayload) bool { |
| 177 | switch payload.EntityType { |
| 178 | case dbCommon.JobEntityType: |
| 179 | job, ok := payload.Payload.(params.Job) |
| 180 | if !ok { |
| 181 | return false |
| 182 | } |
| 183 | |
| 184 | switch ghEntity.EntityType { |
| 185 | case params.ForgeEntityTypeRepository: |
| 186 | if job.RepoID != nil && job.RepoID.String() == ghEntity.ID { |
| 187 | return true |
| 188 | } |
| 189 | case params.ForgeEntityTypeOrganization: |
| 190 | if job.OrgID != nil && job.OrgID.String() == ghEntity.ID { |
| 191 | return true |
| 192 | } |
| 193 | case params.ForgeEntityTypeEnterprise: |
| 194 | if job.EnterpriseID != nil && job.EnterpriseID.String() == ghEntity.ID { |
| 195 | return true |
| 196 | } |
| 197 | } |
| 198 | default: |
| 199 | return false |
| 200 | } |
| 201 | return false |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | // WithForgeCredentialsFilter returns a filter function that filters payloads by Github or Gitea credentials. |
| 206 | func WithForgeCredentialsFilter(creds params.ForgeCredentials) dbCommon.PayloadFilterFunc { |