gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2017 The Gitea Authors. All rights reserved.
  3. // SPDX-License-Identifier: MIT
  4. package structs
  5. import (
  6. "errors"
  7. "strings"
  8. "time"
  9. "code.gitea.io/gitea/modules/json"
  10. )
  11. // ErrInvalidReceiveHook FIXME
  12. var ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webhook")
  13. // Hook a hook is a web hook when one repository changed
  14. type Hook struct {
  15. // The unique identifier of the webhook
  16. ID int64 `json:"id"`
  17. // The type of the webhook (e.g., gitea, slack, discord)
  18. Type string `json:"type"`
  19. // Branch filter pattern to determine which branches trigger the webhook
  20. BranchFilter string `json:"branch_filter"`
  21. // The URL of the webhook endpoint (hidden in JSON)
  22. URL string `json:"-"`
  23. // Configuration settings for the webhook
  24. Config map[string]string `json:"config"`
  25. // List of events that trigger this webhook
  26. Events []string `json:"events"`
  27. // Authorization header to include in webhook requests
  28. AuthorizationHeader string `json:"authorization_header"`
  29. // Whether the webhook is active and will be triggered
  30. Active bool `json:"active"`
  31. // swagger:strfmt date-time
  32. // The date and time when the webhook was last updated
  33. Updated time.Time `json:"updated_at"`
  34. // swagger:strfmt date-time
  35. // The date and time when the webhook was created
  36. Created time.Time `json:"created_at"`
  37. }
  38. // HookList represents a list of API hook.
  39. type HookList []*Hook
  40. // CreateHookOptionConfig has all config options in it
  41. // required are "content_type" and "url" Required
  42. type CreateHookOptionConfig map[string]string
  43. // CreateHookOption options when create a hook
  44. type CreateHookOption struct {
  45. // required: true
  46. // enum: dingtalk,discord,gitea,gogs,msteams,slack,telegram,feishu,wechatwork,packagist
  47. // The type of the webhook to create
  48. Type string `json:"type" binding:"Required"`
  49. // required: true
  50. // Configuration settings for the webhook
  51. Config CreateHookOptionConfig `json:"config" binding:"Required"`
  52. // List of events that will trigger this webhook
  53. Events []string `json:"events"`
  54. // Branch filter pattern to determine which branches trigger the webhook
  55. BranchFilter string `json:"branch_filter" binding:"GlobPattern"`
  56. // Authorization header to include in webhook requests
  57. AuthorizationHeader string `json:"authorization_header"`
  58. // default: false
  59. // Whether the webhook should be active upon creation
  60. Active bool `json:"active"`
  61. }
  62. // EditHookOption options when modify one hook
  63. type EditHookOption struct {
  64. // Configuration settings for the webhook
  65. Config map[string]string `json:"config"`
  66. // List of events that trigger this webhook
  67. Events []string `json:"events"`
  68. // Branch filter pattern to determine which branches trigger the webhook
  69. BranchFilter string `json:"branch_filter" binding:"GlobPattern"`
  70. // Authorization header to include in webhook requests
  71. AuthorizationHeader string `json:"authorization_header"`
  72. // Whether the webhook is active and will be triggered
  73. Active *bool `json:"active"`
  74. }
  75. // Payloader payload is some part of one hook
  76. type Payloader interface {
  77. JSONPayload() ([]byte, error)
  78. }
  79. // PayloadUser represents the author or committer of a commit
  80. type PayloadUser struct {
  81. // Full name of the commit author
  82. Name string `json:"name"`
  83. // swagger:strfmt email
  84. Email string `json:"email"`
  85. // username of the user
  86. UserName string `json:"username"`
  87. }
  88. // FIXME: consider using same format as API when commits API are added.
  89. // applies to PayloadCommit and PayloadCommitVerification
  90. // PayloadCommit represents a commit
  91. type PayloadCommit struct {
  92. // sha1 hash of the commit
  93. ID string `json:"id"`
  94. // The commit message
  95. Message string `json:"message"`
  96. // The URL to view this commit
  97. URL string `json:"url"`
  98. // The author of the commit
  99. Author *PayloadUser `json:"author"`
  100. // The committer of the commit
  101. Committer *PayloadUser `json:"committer"`
  102. // GPG verification information for the commit
  103. Verification *PayloadCommitVerification `json:"verification"`
  104. // swagger:strfmt date-time
  105. // The timestamp when the commit was made
  106. Timestamp time.Time `json:"timestamp"`
  107. // List of files added in this commit
  108. Added []string `json:"added"`
  109. // List of files removed in this commit
  110. Removed []string `json:"removed"`
  111. // List of files modified in this commit
  112. Modified []string `json:"modified"`
  113. }
  114. // PayloadCommitVerification represents the GPG verification of a commit
  115. type PayloadCommitVerification struct {
  116. // Whether the commit signature is verified
  117. Verified bool `json:"verified"`
  118. // The reason for the verification status
  119. Reason string `json:"reason"`
  120. // The GPG signature of the commit
  121. Signature string `json:"signature"`
  122. // The user who signed the commit
  123. Signer *PayloadUser `json:"signer"`
  124. // The signed payload content
  125. Payload string `json:"payload"`
  126. }
  127. var (
  128. _ Payloader = &CreatePayload{}
  129. _ Payloader = &DeletePayload{}
  130. _ Payloader = &ForkPayload{}
  131. _ Payloader = &PushPayload{}
  132. _ Payloader = &IssuePayload{}
  133. _ Payloader = &IssueCommentPayload{}
  134. _ Payloader = &PullRequestPayload{}
  135. _ Payloader = &RepositoryPayload{}
  136. _ Payloader = &ReleasePayload{}
  137. _ Payloader = &PackagePayload{}
  138. )
  139. // CreatePayload represents a payload information of create event.
  140. type CreatePayload struct {
  141. // The SHA hash of the created reference
  142. Sha string `json:"sha"`
  143. // The full name of the created reference
  144. Ref string `json:"ref"`
  145. // The type of reference created (branch or tag)
  146. RefType string `json:"ref_type"`
  147. // The repository where the reference was created
  148. Repo *Repository `json:"repository"`
  149. // The user who created the reference
  150. Sender *User `json:"sender"`
  151. }
  152. // JSONPayload return payload information
  153. func (p *CreatePayload) JSONPayload() ([]byte, error) {
  154. return json.MarshalIndent(p, "", " ")
  155. }
  156. // ParseCreateHook parses create event hook content.
  157. func ParseCreateHook(raw []byte) (*CreatePayload, error) {
  158. hook := new(CreatePayload)
  159. if err := json.Unmarshal(raw, hook); err != nil {
  160. return nil, err
  161. }
  162. // it is possible the JSON was parsed, however,
  163. // was not from Gogs (maybe was from Bitbucket)
  164. // So we'll check to be sure certain key fields
  165. // were populated
  166. switch {
  167. case hook.Repo == nil:
  168. return nil, ErrInvalidReceiveHook
  169. case len(hook.Ref) == 0:
  170. return nil, ErrInvalidReceiveHook
  171. }
  172. return hook, nil
  173. }
  174. // PusherType define the type to push
  175. type PusherType string
  176. // describe all the PusherTypes
  177. const (
  178. PusherTypeUser PusherType = "user"
  179. )
  180. // DeletePayload represents delete payload
  181. type DeletePayload struct {
  182. // The name of the deleted reference
  183. Ref string `json:"ref"`
  184. // The type of reference deleted (branch or tag)
  185. RefType string `json:"ref_type"`
  186. // The type of entity that performed the deletion
  187. PusherType PusherType `json:"pusher_type"`
  188. // The repository where the reference was deleted
  189. Repo *Repository `json:"repository"`
  190. // The user who deleted the reference
  191. Sender *User `json:"sender"`
  192. }
  193. // JSONPayload implements Payload
  194. func (p *DeletePayload) JSONPayload() ([]byte, error) {
  195. return json.MarshalIndent(p, "", " ")
  196. }
  197. // ForkPayload represents fork payload
  198. type ForkPayload struct {
  199. // The forked repository (the new fork)
  200. Forkee *Repository `json:"forkee"`
  201. // The original repository that was forked
  202. Repo *Repository `json:"repository"`
  203. // The user who created the fork
  204. Sender *User `json:"sender"`
  205. }
  206. // JSONPayload implements Payload
  207. func (p *ForkPayload) JSONPayload() ([]byte, error) {
  208. return json.MarshalIndent(p, "", " ")
  209. }
  210. // HookIssueCommentAction defines hook issue comment action
  211. type HookIssueCommentAction string
  212. // all issue comment actions
  213. const (
  214. HookIssueCommentCreated HookIssueCommentAction = "created"
  215. HookIssueCommentEdited HookIssueCommentAction = "edited"
  216. HookIssueCommentDeleted HookIssueCommentAction = "deleted"
  217. )
  218. // IssueCommentPayload represents a payload information of issue comment event.
  219. type IssueCommentPayload struct {
  220. // The action performed on the comment (created, edited, deleted)
  221. Action HookIssueCommentAction `json:"action"`
  222. // The issue that the comment belongs to
  223. Issue *Issue `json:"issue"`
  224. // The pull request if the comment is on a pull request
  225. PullRequest *PullRequest `json:"pull_request,omitempty"`
  226. // The comment that was acted upon
  227. Comment *Comment `json:"comment"`
  228. // Changes made to the comment (for edit actions)
  229. Changes *ChangesPayload `json:"changes,omitempty"`
  230. // The repository containing the issue/pull request
  231. Repository *Repository `json:"repository"`
  232. // The user who performed the action
  233. Sender *User `json:"sender"`
  234. // Whether this comment is on a pull request
  235. IsPull bool `json:"is_pull"`
  236. }
  237. // JSONPayload implements Payload
  238. func (p *IssueCommentPayload) JSONPayload() ([]byte, error) {
  239. return json.MarshalIndent(p, "", " ")
  240. }
  241. // HookReleaseAction defines hook release action type
  242. type HookReleaseAction string
  243. // all release actions
  244. const (
  245. HookReleasePublished HookReleaseAction = "published"
  246. HookReleaseUpdated HookReleaseAction = "updated"
  247. HookReleaseDeleted HookReleaseAction = "deleted"
  248. )
  249. // ReleasePayload represents a payload information of release event.
  250. type ReleasePayload struct {
  251. // The action performed on the release (published, updated, deleted)
  252. Action HookReleaseAction `json:"action"`
  253. // The release that was acted upon
  254. Release *Release `json:"release"`
  255. // The repository containing the release
  256. Repository *Repository `json:"repository"`
  257. // The user who performed the action
  258. Sender *User `json:"sender"`
  259. }
  260. // JSONPayload implements Payload
  261. func (p *ReleasePayload) JSONPayload() ([]byte, error) {
  262. return json.MarshalIndent(p, "", " ")
  263. }
  264. // PushPayload represents a payload information of push event.
  265. type PushPayload struct {
  266. // The full name of the pushed reference
  267. Ref string `json:"ref"`
  268. // The SHA of the most recent commit before the push
  269. Before string `json:"before"`
  270. // The SHA of the most recent commit after the push
  271. After string `json:"after"`
  272. // URL to compare the changes in this push
  273. CompareURL string `json:"compare_url"`
  274. // List of commits included in the push
  275. Commits []*PayloadCommit `json:"commits"`
  276. // Total number of commits in the push
  277. TotalCommits int `json:"total_commits"`
  278. // The most recent commit in the push
  279. HeadCommit *PayloadCommit `json:"head_commit"`
  280. // The repository that was pushed to
  281. Repo *Repository `json:"repository"`
  282. // The user who performed the push
  283. Pusher *User `json:"pusher"`
  284. // The user who triggered the webhook
  285. Sender *User `json:"sender"`
  286. }
  287. // JSONPayload FIXME
  288. func (p *PushPayload) JSONPayload() ([]byte, error) {
  289. return json.MarshalIndent(p, "", " ")
  290. }
  291. // ParsePushHook parses push event hook content.
  292. func ParsePushHook(raw []byte) (*PushPayload, error) {
  293. hook := new(PushPayload)
  294. if err := json.Unmarshal(raw, hook); err != nil {
  295. return nil, err
  296. }
  297. switch {
  298. case hook.Repo == nil:
  299. return nil, ErrInvalidReceiveHook
  300. case len(hook.Ref) == 0:
  301. return nil, ErrInvalidReceiveHook
  302. }
  303. return hook, nil
  304. }
  305. // Branch returns branch name from a payload
  306. func (p *PushPayload) Branch() string {
  307. return strings.ReplaceAll(p.Ref, "refs/heads/", "")
  308. }
  309. // HookIssueAction FIXME
  310. type HookIssueAction string
  311. const (
  312. // HookIssueOpened opened
  313. HookIssueOpened HookIssueAction = "opened"
  314. // HookIssueClosed closed
  315. HookIssueClosed HookIssueAction = "closed"
  316. // HookIssueReOpened reopened
  317. HookIssueReOpened HookIssueAction = "reopened"
  318. // HookIssueEdited edited
  319. HookIssueEdited HookIssueAction = "edited"
  320. // HookIssueDeleted is an issue action for deleting an issue
  321. HookIssueDeleted HookIssueAction = "deleted"
  322. // HookIssueAssigned assigned
  323. HookIssueAssigned HookIssueAction = "assigned"
  324. // HookIssueUnassigned unassigned
  325. HookIssueUnassigned HookIssueAction = "unassigned"
  326. // HookIssueLabelUpdated label_updated
  327. HookIssueLabelUpdated HookIssueAction = "label_updated"
  328. // HookIssueLabelCleared label_cleared
  329. HookIssueLabelCleared HookIssueAction = "label_cleared"
  330. // HookIssueSynchronized synchronized
  331. HookIssueSynchronized HookIssueAction = "synchronized"
  332. // HookIssueMilestoned is an issue action for when a milestone is set on an issue.
  333. HookIssueMilestoned HookIssueAction = "milestoned"
  334. // HookIssueDemilestoned is an issue action for when a milestone is cleared on an issue.
  335. HookIssueDemilestoned HookIssueAction = "demilestoned"
  336. // HookIssueReviewed is an issue action for when a pull request is reviewed
  337. HookIssueReviewed HookIssueAction = "reviewed"
  338. // HookIssueReviewRequested is an issue action for when a reviewer is requested for a pull request.
  339. HookIssueReviewRequested HookIssueAction = "review_requested"
  340. // HookIssueReviewRequestRemoved is an issue action for removing a review request to someone on a pull request.
  341. HookIssueReviewRequestRemoved HookIssueAction = "review_request_removed"
  342. )
  343. // IssuePayload represents the payload information that is sent along with an issue event.
  344. type IssuePayload struct {
  345. // The action performed on the issue
  346. Action HookIssueAction `json:"action"`
  347. // The index number of the issue
  348. Index int64 `json:"number"`
  349. // Changes made to the issue (for edit actions)
  350. Changes *ChangesPayload `json:"changes,omitempty"`
  351. // The issue that was acted upon
  352. Issue *Issue `json:"issue"`
  353. // The repository containing the issue
  354. Repository *Repository `json:"repository"`
  355. // The user who performed the action
  356. Sender *User `json:"sender"`
  357. // The commit ID related to the issue action
  358. CommitID string `json:"commit_id"`
  359. }
  360. // JSONPayload encodes the IssuePayload to JSON, with an indentation of two spaces.
  361. func (p *IssuePayload) JSONPayload() ([]byte, error) {
  362. return json.MarshalIndent(p, "", " ")
  363. }
  364. // ChangesFromPayload FIXME
  365. type ChangesFromPayload struct {
  366. // The previous value before the change
  367. From string `json:"from"`
  368. }
  369. // ChangesPayload represents the payload information of issue change
  370. type ChangesPayload struct {
  371. // Changes made to the title
  372. Title *ChangesFromPayload `json:"title,omitempty"`
  373. // Changes made to the body/description
  374. Body *ChangesFromPayload `json:"body,omitempty"`
  375. // Changes made to the reference
  376. Ref *ChangesFromPayload `json:"ref,omitempty"`
  377. // Changes made to the labels added
  378. AddedLabels []*Label `json:"added_labels"`
  379. // Changes made to the labels removed
  380. RemovedLabels []*Label `json:"removed_labels"`
  381. }
  382. // PullRequestPayload represents a payload information of pull request event.
  383. type PullRequestPayload struct {
  384. // The action performed on the pull request
  385. Action HookIssueAction `json:"action"`
  386. // The index number of the pull request
  387. Index int64 `json:"number"`
  388. // Changes made to the pull request (for edit actions)
  389. Changes *ChangesPayload `json:"changes,omitempty"`
  390. // The pull request that was acted upon
  391. PullRequest *PullRequest `json:"pull_request"`
  392. // The reviewer that was requested (for review request actions)
  393. RequestedReviewer *User `json:"requested_reviewer"`
  394. // The repository containing the pull request
  395. Repository *Repository `json:"repository"`
  396. // The user who performed the action
  397. Sender *User `json:"sender"`
  398. // The commit ID related to the pull request action
  399. CommitID string `json:"commit_id"`
  400. // The review information (for review actions)
  401. Review *ReviewPayload `json:"review"`
  402. }
  403. // JSONPayload FIXME
  404. func (p *PullRequestPayload) JSONPayload() ([]byte, error) {
  405. return json.MarshalIndent(p, "", " ")
  406. }
  407. // ReviewPayload FIXME
  408. type ReviewPayload struct {
  409. // The type of review (approved, rejected, comment)
  410. Type string `json:"type"`
  411. // The content/body of the review
  412. Content string `json:"content"`
  413. }
  414. // HookWikiAction an action that happens to a wiki page
  415. type HookWikiAction string
  416. const (
  417. // HookWikiCreated created
  418. HookWikiCreated HookWikiAction = "created"
  419. // HookWikiEdited edited
  420. HookWikiEdited HookWikiAction = "edited"
  421. // HookWikiDeleted deleted
  422. HookWikiDeleted HookWikiAction = "deleted"
  423. )
  424. // WikiPayload payload for repository webhooks
  425. type WikiPayload struct {
  426. // The action performed on the wiki page
  427. Action HookWikiAction `json:"action"`
  428. // The repository containing the wiki
  429. Repository *Repository `json:"repository"`
  430. // The user who performed the action
  431. Sender *User `json:"sender"`
  432. // The name of the wiki page
  433. Page string `json:"page"`
  434. // The comment/commit message for the wiki change
  435. Comment string `json:"comment"`
  436. }
  437. // JSONPayload JSON representation of the payload
  438. func (p *WikiPayload) JSONPayload() ([]byte, error) {
  439. return json.MarshalIndent(p, "", " ")
  440. }
  441. // HookRepoAction an action that happens to a repo
  442. type HookRepoAction string
  443. const (
  444. // HookRepoCreated created
  445. HookRepoCreated HookRepoAction = "created"
  446. // HookRepoDeleted deleted
  447. HookRepoDeleted HookRepoAction = "deleted"
  448. )
  449. // RepositoryPayload payload for repository webhooks
  450. type RepositoryPayload struct {
  451. // The action performed on the repository
  452. Action HookRepoAction `json:"action"`
  453. // The repository that was acted upon
  454. Repository *Repository `json:"repository"`
  455. // The organization that owns the repository (if applicable)
  456. Organization *User `json:"organization"`
  457. // The user who performed the action
  458. Sender *User `json:"sender"`
  459. }
  460. // JSONPayload JSON representation of the payload
  461. func (p *RepositoryPayload) JSONPayload() ([]byte, error) {
  462. return json.MarshalIndent(p, "", " ")
  463. }
  464. // HookPackageAction an action that happens to a package
  465. type HookPackageAction string
  466. const (
  467. // HookPackageCreated created
  468. HookPackageCreated HookPackageAction = "created"
  469. // HookPackageDeleted deleted
  470. HookPackageDeleted HookPackageAction = "deleted"
  471. )
  472. // PackagePayload represents a package payload
  473. type PackagePayload struct {
  474. // The action performed on the package
  475. Action HookPackageAction `json:"action"`
  476. // The repository associated with the package
  477. Repository *Repository `json:"repository"`
  478. // The package that was acted upon
  479. Package *Package `json:"package"`
  480. // The organization that owns the package (if applicable)
  481. Organization *Organization `json:"organization"`
  482. // The user who performed the action
  483. Sender *User `json:"sender"`
  484. }
  485. // JSONPayload implements Payload
  486. func (p *PackagePayload) JSONPayload() ([]byte, error) {
  487. return json.MarshalIndent(p, "", " ")
  488. }
  489. // WorkflowDispatchPayload represents a workflow dispatch payload
  490. type WorkflowDispatchPayload struct {
  491. // The name or path of the workflow file
  492. Workflow string `json:"workflow"`
  493. // The git reference (branch, tag, or commit SHA) to run the workflow on
  494. Ref string `json:"ref"`
  495. // Input parameters for the workflow dispatch event
  496. Inputs map[string]any `json:"inputs"`
  497. // The repository containing the workflow
  498. Repository *Repository `json:"repository"`
  499. // The user who triggered the workflow dispatch
  500. Sender *User `json:"sender"`
  501. }
  502. // JSONPayload implements Payload
  503. func (p *WorkflowDispatchPayload) JSONPayload() ([]byte, error) {
  504. return json.MarshalIndent(p, "", " ")
  505. }
  506. // CommitStatusPayload represents a payload information of commit status event.
  507. type CommitStatusPayload struct {
  508. // TODO: add Branches per https://docs.github.com/en/webhooks/webhook-events-and-payloads#status
  509. // The commit that the status is associated with
  510. Commit *PayloadCommit `json:"commit"`
  511. // The context/identifier for this status check
  512. Context string `json:"context"`
  513. // swagger:strfmt date-time
  514. // The date and time when the status was created
  515. CreatedAt time.Time `json:"created_at"`
  516. // A short description of the status
  517. Description string `json:"description"`
  518. // The unique identifier of the status
  519. ID int64 `json:"id"`
  520. // The repository containing the commit
  521. Repo *Repository `json:"repository"`
  522. // The user who created the status
  523. Sender *User `json:"sender"`
  524. // The SHA hash of the commit
  525. SHA string `json:"sha"`
  526. // The state of the status (pending, success, error, failure)
  527. State string `json:"state"`
  528. // The target URL to associate with this status
  529. TargetURL string `json:"target_url"`
  530. // swagger:strfmt date-time
  531. // The date and time when the status was last updated
  532. UpdatedAt *time.Time `json:"updated_at"`
  533. }
  534. // JSONPayload implements Payload
  535. func (p *CommitStatusPayload) JSONPayload() ([]byte, error) {
  536. return json.MarshalIndent(p, "", " ")
  537. }
  538. // WorkflowRunPayload represents a payload information of workflow run event.
  539. type WorkflowRunPayload struct {
  540. // The action performed on the workflow run
  541. Action string `json:"action"`
  542. // The workflow definition
  543. Workflow *ActionWorkflow `json:"workflow"`
  544. // The workflow run that was acted upon
  545. WorkflowRun *ActionWorkflowRun `json:"workflow_run"`
  546. // The pull request associated with the workflow run (if applicable)
  547. PullRequest *PullRequest `json:"pull_request,omitempty"`
  548. // The organization that owns the repository (if applicable)
  549. Organization *Organization `json:"organization,omitempty"`
  550. // The repository containing the workflow
  551. Repo *Repository `json:"repository"`
  552. // The user who triggered the workflow run
  553. Sender *User `json:"sender"`
  554. }
  555. // JSONPayload implements Payload
  556. func (p *WorkflowRunPayload) JSONPayload() ([]byte, error) {
  557. return json.MarshalIndent(p, "", " ")
  558. }
  559. // WorkflowJobPayload represents a payload information of workflow job event.
  560. type WorkflowJobPayload struct {
  561. // The action performed on the workflow job
  562. Action string `json:"action"`
  563. // The workflow job that was acted upon
  564. WorkflowJob *ActionWorkflowJob `json:"workflow_job"`
  565. // The pull request associated with the workflow job (if applicable)
  566. PullRequest *PullRequest `json:"pull_request,omitempty"`
  567. // The organization that owns the repository (if applicable)
  568. Organization *Organization `json:"organization,omitempty"`
  569. // The repository containing the workflow
  570. Repo *Repository `json:"repository"`
  571. // The user who triggered the workflow job
  572. Sender *User `json:"sender"`
  573. }
  574. // JSONPayload implements Payload
  575. func (p *WorkflowJobPayload) JSONPayload() ([]byte, error) {
  576. return json.MarshalIndent(p, "", " ")
  577. }