本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

730 lines
19KB

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "encoding/json"
  7. "fmt"
  8. "strings"
  9. "code.gitea.io/gitea/modules/git"
  10. api "code.gitea.io/gitea/modules/structs"
  11. )
  12. type (
  13. // MSTeamsFact for Fact Structure
  14. MSTeamsFact struct {
  15. Name string `json:"name"`
  16. Value string `json:"value"`
  17. }
  18. // MSTeamsSection is a MessageCard section
  19. MSTeamsSection struct {
  20. ActivityTitle string `json:"activityTitle"`
  21. ActivitySubtitle string `json:"activitySubtitle"`
  22. ActivityImage string `json:"activityImage"`
  23. Facts []MSTeamsFact `json:"facts"`
  24. Text string `json:"text"`
  25. }
  26. // MSTeamsAction is an action (creates buttons, links etc)
  27. MSTeamsAction struct {
  28. Type string `json:"@type"`
  29. Name string `json:"name"`
  30. Targets []MSTeamsActionTarget `json:"targets,omitempty"`
  31. }
  32. // MSTeamsActionTarget is the actual link to follow, etc
  33. MSTeamsActionTarget struct {
  34. Os string `json:"os"`
  35. URI string `json:"uri"`
  36. }
  37. // MSTeamsPayload is the parent object
  38. MSTeamsPayload struct {
  39. Type string `json:"@type"`
  40. Context string `json:"@context"`
  41. ThemeColor string `json:"themeColor"`
  42. Title string `json:"title"`
  43. Summary string `json:"summary"`
  44. Sections []MSTeamsSection `json:"sections"`
  45. PotentialAction []MSTeamsAction `json:"potentialAction"`
  46. }
  47. )
  48. // SetSecret sets the MSTeams secret
  49. func (p *MSTeamsPayload) SetSecret(_ string) {}
  50. // JSONPayload Marshals the MSTeamsPayload to json
  51. func (p *MSTeamsPayload) JSONPayload() ([]byte, error) {
  52. data, err := json.MarshalIndent(p, "", " ")
  53. if err != nil {
  54. return []byte{}, err
  55. }
  56. return data, nil
  57. }
  58. func getMSTeamsCreatePayload(p *api.CreatePayload) (*MSTeamsPayload, error) {
  59. // created tag/branch
  60. refName := git.RefEndName(p.Ref)
  61. title := fmt.Sprintf("[%s] %s %s created", p.Repo.FullName, p.RefType, refName)
  62. return &MSTeamsPayload{
  63. Type: "MessageCard",
  64. Context: "https://schema.org/extensions",
  65. ThemeColor: fmt.Sprintf("%x", greenColor),
  66. Title: title,
  67. Summary: title,
  68. Sections: []MSTeamsSection{
  69. {
  70. ActivityTitle: p.Sender.FullName,
  71. ActivitySubtitle: p.Sender.UserName,
  72. ActivityImage: p.Sender.AvatarURL,
  73. Facts: []MSTeamsFact{
  74. {
  75. Name: "Repository:",
  76. Value: p.Repo.FullName,
  77. },
  78. {
  79. Name: fmt.Sprintf("%s:", p.RefType),
  80. Value: refName,
  81. },
  82. },
  83. },
  84. },
  85. PotentialAction: []MSTeamsAction{
  86. {
  87. Type: "OpenUri",
  88. Name: "View in Gitea",
  89. Targets: []MSTeamsActionTarget{
  90. {
  91. Os: "default",
  92. URI: p.Repo.HTMLURL + "/src/" + refName,
  93. },
  94. },
  95. },
  96. },
  97. }, nil
  98. }
  99. func getMSTeamsDeletePayload(p *api.DeletePayload) (*MSTeamsPayload, error) {
  100. // deleted tag/branch
  101. refName := git.RefEndName(p.Ref)
  102. title := fmt.Sprintf("[%s] %s %s deleted", p.Repo.FullName, p.RefType, refName)
  103. return &MSTeamsPayload{
  104. Type: "MessageCard",
  105. Context: "https://schema.org/extensions",
  106. ThemeColor: fmt.Sprintf("%x", yellowColor),
  107. Title: title,
  108. Summary: title,
  109. Sections: []MSTeamsSection{
  110. {
  111. ActivityTitle: p.Sender.FullName,
  112. ActivitySubtitle: p.Sender.UserName,
  113. ActivityImage: p.Sender.AvatarURL,
  114. Facts: []MSTeamsFact{
  115. {
  116. Name: "Repository:",
  117. Value: p.Repo.FullName,
  118. },
  119. {
  120. Name: fmt.Sprintf("%s:", p.RefType),
  121. Value: refName,
  122. },
  123. },
  124. },
  125. },
  126. PotentialAction: []MSTeamsAction{
  127. {
  128. Type: "OpenUri",
  129. Name: "View in Gitea",
  130. Targets: []MSTeamsActionTarget{
  131. {
  132. Os: "default",
  133. URI: p.Repo.HTMLURL + "/src/" + refName,
  134. },
  135. },
  136. },
  137. },
  138. }, nil
  139. }
  140. func getMSTeamsForkPayload(p *api.ForkPayload) (*MSTeamsPayload, error) {
  141. // fork
  142. title := fmt.Sprintf("%s is forked to %s", p.Forkee.FullName, p.Repo.FullName)
  143. return &MSTeamsPayload{
  144. Type: "MessageCard",
  145. Context: "https://schema.org/extensions",
  146. ThemeColor: fmt.Sprintf("%x", greenColor),
  147. Title: title,
  148. Summary: title,
  149. Sections: []MSTeamsSection{
  150. {
  151. ActivityTitle: p.Sender.FullName,
  152. ActivitySubtitle: p.Sender.UserName,
  153. ActivityImage: p.Sender.AvatarURL,
  154. Facts: []MSTeamsFact{
  155. {
  156. Name: "Forkee:",
  157. Value: p.Forkee.FullName,
  158. },
  159. {
  160. Name: "Repository:",
  161. Value: p.Repo.FullName,
  162. },
  163. },
  164. },
  165. },
  166. PotentialAction: []MSTeamsAction{
  167. {
  168. Type: "OpenUri",
  169. Name: "View in Gitea",
  170. Targets: []MSTeamsActionTarget{
  171. {
  172. Os: "default",
  173. URI: p.Repo.HTMLURL,
  174. },
  175. },
  176. },
  177. },
  178. }, nil
  179. }
  180. func getMSTeamsPushPayload(p *api.PushPayload) (*MSTeamsPayload, error) {
  181. var (
  182. branchName = git.RefEndName(p.Ref)
  183. commitDesc string
  184. )
  185. var titleLink string
  186. if len(p.Commits) == 1 {
  187. commitDesc = "1 new commit"
  188. titleLink = p.Commits[0].URL
  189. } else {
  190. commitDesc = fmt.Sprintf("%d new commits", len(p.Commits))
  191. titleLink = p.CompareURL
  192. }
  193. if titleLink == "" {
  194. titleLink = p.Repo.HTMLURL + "/src/" + branchName
  195. }
  196. title := fmt.Sprintf("[%s:%s] %s", p.Repo.FullName, branchName, commitDesc)
  197. var text string
  198. // for each commit, generate attachment text
  199. for i, commit := range p.Commits {
  200. text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL,
  201. strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name)
  202. // add linebreak to each commit but the last
  203. if i < len(p.Commits)-1 {
  204. text += "\n"
  205. }
  206. }
  207. return &MSTeamsPayload{
  208. Type: "MessageCard",
  209. Context: "https://schema.org/extensions",
  210. ThemeColor: fmt.Sprintf("%x", greenColor),
  211. Title: title,
  212. Summary: title,
  213. Sections: []MSTeamsSection{
  214. {
  215. ActivityTitle: p.Sender.FullName,
  216. ActivitySubtitle: p.Sender.UserName,
  217. ActivityImage: p.Sender.AvatarURL,
  218. Text: text,
  219. Facts: []MSTeamsFact{
  220. {
  221. Name: "Repository:",
  222. Value: p.Repo.FullName,
  223. },
  224. {
  225. Name: "Commit count:",
  226. Value: fmt.Sprintf("%d", len(p.Commits)),
  227. },
  228. },
  229. },
  230. },
  231. PotentialAction: []MSTeamsAction{
  232. {
  233. Type: "OpenUri",
  234. Name: "View in Gitea",
  235. Targets: []MSTeamsActionTarget{
  236. {
  237. Os: "default",
  238. URI: titleLink,
  239. },
  240. },
  241. },
  242. },
  243. }, nil
  244. }
  245. func getMSTeamsIssuesPayload(p *api.IssuePayload) (*MSTeamsPayload, error) {
  246. var text, title string
  247. var color int
  248. url := fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Issue.Index)
  249. switch p.Action {
  250. case api.HookIssueOpened:
  251. title = fmt.Sprintf("[%s] Issue opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
  252. text = p.Issue.Body
  253. color = orangeColor
  254. case api.HookIssueClosed:
  255. title = fmt.Sprintf("[%s] Issue closed: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
  256. color = redColor
  257. text = p.Issue.Body
  258. case api.HookIssueReOpened:
  259. title = fmt.Sprintf("[%s] Issue re-opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
  260. text = p.Issue.Body
  261. color = yellowColor
  262. case api.HookIssueEdited:
  263. title = fmt.Sprintf("[%s] Issue edited: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
  264. text = p.Issue.Body
  265. color = yellowColor
  266. case api.HookIssueAssigned:
  267. title = fmt.Sprintf("[%s] Issue assigned to %s: #%d %s", p.Repository.FullName,
  268. p.Issue.Assignee.UserName, p.Index, p.Issue.Title)
  269. text = p.Issue.Body
  270. color = greenColor
  271. case api.HookIssueUnassigned:
  272. title = fmt.Sprintf("[%s] Issue unassigned: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
  273. text = p.Issue.Body
  274. color = yellowColor
  275. case api.HookIssueLabelUpdated:
  276. title = fmt.Sprintf("[%s] Issue labels updated: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
  277. text = p.Issue.Body
  278. color = yellowColor
  279. case api.HookIssueLabelCleared:
  280. title = fmt.Sprintf("[%s] Issue labels cleared: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
  281. text = p.Issue.Body
  282. color = yellowColor
  283. case api.HookIssueSynchronized:
  284. title = fmt.Sprintf("[%s] Issue synchronized: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
  285. text = p.Issue.Body
  286. color = yellowColor
  287. case api.HookIssueMilestoned:
  288. title = fmt.Sprintf("[%s] Issue milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
  289. text = p.Issue.Body
  290. color = yellowColor
  291. case api.HookIssueDemilestoned:
  292. title = fmt.Sprintf("[%s] Issue clear milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
  293. text = p.Issue.Body
  294. color = yellowColor
  295. }
  296. return &MSTeamsPayload{
  297. Type: "MessageCard",
  298. Context: "https://schema.org/extensions",
  299. ThemeColor: fmt.Sprintf("%x", color),
  300. Title: title,
  301. Summary: title,
  302. Sections: []MSTeamsSection{
  303. {
  304. ActivityTitle: p.Sender.FullName,
  305. ActivitySubtitle: p.Sender.UserName,
  306. ActivityImage: p.Sender.AvatarURL,
  307. Text: text,
  308. Facts: []MSTeamsFact{
  309. {
  310. Name: "Repository:",
  311. Value: p.Repository.FullName,
  312. },
  313. {
  314. Name: "Issue #:",
  315. Value: fmt.Sprintf("%d", p.Issue.ID),
  316. },
  317. },
  318. },
  319. },
  320. PotentialAction: []MSTeamsAction{
  321. {
  322. Type: "OpenUri",
  323. Name: "View in Gitea",
  324. Targets: []MSTeamsActionTarget{
  325. {
  326. Os: "default",
  327. URI: url,
  328. },
  329. },
  330. },
  331. },
  332. }, nil
  333. }
  334. func getMSTeamsIssueCommentPayload(p *api.IssueCommentPayload) (*MSTeamsPayload, error) {
  335. title := fmt.Sprintf("#%d: %s", p.Issue.Index, p.Issue.Title)
  336. url := fmt.Sprintf("%s/issues/%d#%s", p.Repository.HTMLURL, p.Issue.Index, CommentHashTag(p.Comment.ID))
  337. content := ""
  338. var color int
  339. switch p.Action {
  340. case api.HookIssueCommentCreated:
  341. if p.IsPull {
  342. title = "New comment on pull request " + title
  343. color = greenColorLight
  344. } else {
  345. title = "New comment on issue " + title
  346. color = orangeColorLight
  347. }
  348. content = p.Comment.Body
  349. case api.HookIssueCommentEdited:
  350. if p.IsPull {
  351. title = "Comment edited on pull request " + title
  352. } else {
  353. title = "Comment edited on issue " + title
  354. }
  355. content = p.Comment.Body
  356. color = yellowColor
  357. case api.HookIssueCommentDeleted:
  358. if p.IsPull {
  359. title = "Comment deleted on pull request " + title
  360. } else {
  361. title = "Comment deleted on issue " + title
  362. }
  363. url = fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Issue.Index)
  364. content = p.Comment.Body
  365. color = redColor
  366. }
  367. title = fmt.Sprintf("[%s] %s", p.Repository.FullName, title)
  368. return &MSTeamsPayload{
  369. Type: "MessageCard",
  370. Context: "https://schema.org/extensions",
  371. ThemeColor: fmt.Sprintf("%x", color),
  372. Title: title,
  373. Summary: title,
  374. Sections: []MSTeamsSection{
  375. {
  376. ActivityTitle: p.Sender.FullName,
  377. ActivitySubtitle: p.Sender.UserName,
  378. ActivityImage: p.Sender.AvatarURL,
  379. Text: content,
  380. Facts: []MSTeamsFact{
  381. {
  382. Name: "Repository:",
  383. Value: p.Repository.FullName,
  384. },
  385. {
  386. Name: "Issue #:",
  387. Value: fmt.Sprintf("%d", p.Issue.ID),
  388. },
  389. },
  390. },
  391. },
  392. PotentialAction: []MSTeamsAction{
  393. {
  394. Type: "OpenUri",
  395. Name: "View in Gitea",
  396. Targets: []MSTeamsActionTarget{
  397. {
  398. Os: "default",
  399. URI: url,
  400. },
  401. },
  402. },
  403. },
  404. }, nil
  405. }
  406. func getMSTeamsPullRequestPayload(p *api.PullRequestPayload) (*MSTeamsPayload, error) {
  407. var text, title string
  408. var color int
  409. switch p.Action {
  410. case api.HookIssueOpened:
  411. title = fmt.Sprintf("[%s] Pull request opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
  412. text = p.PullRequest.Body
  413. color = greenColor
  414. case api.HookIssueClosed:
  415. if p.PullRequest.HasMerged {
  416. title = fmt.Sprintf("[%s] Pull request merged: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
  417. color = purpleColor
  418. } else {
  419. title = fmt.Sprintf("[%s] Pull request closed: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
  420. color = redColor
  421. }
  422. text = p.PullRequest.Body
  423. case api.HookIssueReOpened:
  424. title = fmt.Sprintf("[%s] Pull request re-opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
  425. text = p.PullRequest.Body
  426. color = yellowColor
  427. case api.HookIssueEdited:
  428. title = fmt.Sprintf("[%s] Pull request edited: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
  429. text = p.PullRequest.Body
  430. color = yellowColor
  431. case api.HookIssueAssigned:
  432. list := make([]string, len(p.PullRequest.Assignees))
  433. for i, user := range p.PullRequest.Assignees {
  434. list[i] = user.UserName
  435. }
  436. title = fmt.Sprintf("[%s] Pull request assigned to %s: #%d by %s", p.Repository.FullName,
  437. strings.Join(list, ", "),
  438. p.Index, p.PullRequest.Title)
  439. text = p.PullRequest.Body
  440. color = greenColor
  441. case api.HookIssueUnassigned:
  442. title = fmt.Sprintf("[%s] Pull request unassigned: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
  443. text = p.PullRequest.Body
  444. color = yellowColor
  445. case api.HookIssueLabelUpdated:
  446. title = fmt.Sprintf("[%s] Pull request labels updated: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
  447. text = p.PullRequest.Body
  448. color = yellowColor
  449. case api.HookIssueLabelCleared:
  450. title = fmt.Sprintf("[%s] Pull request labels cleared: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
  451. text = p.PullRequest.Body
  452. color = yellowColor
  453. case api.HookIssueSynchronized:
  454. title = fmt.Sprintf("[%s] Pull request synchronized: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
  455. text = p.PullRequest.Body
  456. color = yellowColor
  457. case api.HookIssueMilestoned:
  458. title = fmt.Sprintf("[%s] Pull request milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
  459. text = p.PullRequest.Body
  460. color = yellowColor
  461. case api.HookIssueDemilestoned:
  462. title = fmt.Sprintf("[%s] Pull request clear milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
  463. text = p.PullRequest.Body
  464. color = yellowColor
  465. }
  466. return &MSTeamsPayload{
  467. Type: "MessageCard",
  468. Context: "https://schema.org/extensions",
  469. ThemeColor: fmt.Sprintf("%x", color),
  470. Title: title,
  471. Summary: title,
  472. Sections: []MSTeamsSection{
  473. {
  474. ActivityTitle: p.Sender.FullName,
  475. ActivitySubtitle: p.Sender.UserName,
  476. ActivityImage: p.Sender.AvatarURL,
  477. Text: text,
  478. Facts: []MSTeamsFact{
  479. {
  480. Name: "Repository:",
  481. Value: p.Repository.FullName,
  482. },
  483. {
  484. Name: "Pull request #:",
  485. Value: fmt.Sprintf("%d", p.PullRequest.ID),
  486. },
  487. },
  488. },
  489. },
  490. PotentialAction: []MSTeamsAction{
  491. {
  492. Type: "OpenUri",
  493. Name: "View in Gitea",
  494. Targets: []MSTeamsActionTarget{
  495. {
  496. Os: "default",
  497. URI: p.PullRequest.HTMLURL,
  498. },
  499. },
  500. },
  501. },
  502. }, nil
  503. }
  504. func getMSTeamsPullRequestApprovalPayload(p *api.PullRequestPayload, event HookEventType) (*MSTeamsPayload, error) {
  505. var text, title string
  506. var color int
  507. switch p.Action {
  508. case api.HookIssueSynchronized:
  509. action, err := parseHookPullRequestEventType(event)
  510. if err != nil {
  511. return nil, err
  512. }
  513. title = fmt.Sprintf("[%s] Pull request review %s: #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title)
  514. text = p.Review.Content
  515. switch event {
  516. case HookEventPullRequestApproved:
  517. color = greenColor
  518. case HookEventPullRequestRejected:
  519. color = redColor
  520. case HookEventPullRequestComment:
  521. color = greyColor
  522. default:
  523. color = yellowColor
  524. }
  525. }
  526. return &MSTeamsPayload{
  527. Type: "MessageCard",
  528. Context: "https://schema.org/extensions",
  529. ThemeColor: fmt.Sprintf("%x", color),
  530. Title: title,
  531. Summary: title,
  532. Sections: []MSTeamsSection{
  533. {
  534. ActivityTitle: p.Sender.FullName,
  535. ActivitySubtitle: p.Sender.UserName,
  536. ActivityImage: p.Sender.AvatarURL,
  537. Text: text,
  538. Facts: []MSTeamsFact{
  539. {
  540. Name: "Repository:",
  541. Value: p.Repository.FullName,
  542. },
  543. {
  544. Name: "Pull request #:",
  545. Value: fmt.Sprintf("%d", p.PullRequest.ID),
  546. },
  547. },
  548. },
  549. },
  550. PotentialAction: []MSTeamsAction{
  551. {
  552. Type: "OpenUri",
  553. Name: "View in Gitea",
  554. Targets: []MSTeamsActionTarget{
  555. {
  556. Os: "default",
  557. URI: p.PullRequest.HTMLURL,
  558. },
  559. },
  560. },
  561. },
  562. }, nil
  563. }
  564. func getMSTeamsRepositoryPayload(p *api.RepositoryPayload) (*MSTeamsPayload, error) {
  565. var title, url string
  566. var color int
  567. switch p.Action {
  568. case api.HookRepoCreated:
  569. title = fmt.Sprintf("[%s] Repository created", p.Repository.FullName)
  570. url = p.Repository.HTMLURL
  571. color = greenColor
  572. case api.HookRepoDeleted:
  573. title = fmt.Sprintf("[%s] Repository deleted", p.Repository.FullName)
  574. color = yellowColor
  575. }
  576. return &MSTeamsPayload{
  577. Type: "MessageCard",
  578. Context: "https://schema.org/extensions",
  579. ThemeColor: fmt.Sprintf("%x", color),
  580. Title: title,
  581. Summary: title,
  582. Sections: []MSTeamsSection{
  583. {
  584. ActivityTitle: p.Sender.FullName,
  585. ActivitySubtitle: p.Sender.UserName,
  586. ActivityImage: p.Sender.AvatarURL,
  587. Facts: []MSTeamsFact{
  588. {
  589. Name: "Repository:",
  590. Value: p.Repository.FullName,
  591. },
  592. },
  593. },
  594. },
  595. PotentialAction: []MSTeamsAction{
  596. {
  597. Type: "OpenUri",
  598. Name: "View in Gitea",
  599. Targets: []MSTeamsActionTarget{
  600. {
  601. Os: "default",
  602. URI: url,
  603. },
  604. },
  605. },
  606. },
  607. }, nil
  608. }
  609. func getMSTeamsReleasePayload(p *api.ReleasePayload) (*MSTeamsPayload, error) {
  610. var title, url string
  611. var color int
  612. switch p.Action {
  613. case api.HookReleasePublished:
  614. title = fmt.Sprintf("[%s] Release created", p.Release.TagName)
  615. url = p.Release.URL
  616. color = greenColor
  617. case api.HookReleaseUpdated:
  618. title = fmt.Sprintf("[%s] Release updated", p.Release.TagName)
  619. url = p.Release.URL
  620. color = greenColor
  621. case api.HookReleaseDeleted:
  622. title = fmt.Sprintf("[%s] Release deleted", p.Release.TagName)
  623. url = p.Release.URL
  624. color = greenColor
  625. }
  626. return &MSTeamsPayload{
  627. Type: "MessageCard",
  628. Context: "https://schema.org/extensions",
  629. ThemeColor: fmt.Sprintf("%x", color),
  630. Title: title,
  631. Summary: title,
  632. Sections: []MSTeamsSection{
  633. {
  634. ActivityTitle: p.Sender.FullName,
  635. ActivitySubtitle: p.Sender.UserName,
  636. ActivityImage: p.Sender.AvatarURL,
  637. Text: p.Release.Note,
  638. Facts: []MSTeamsFact{
  639. {
  640. Name: "Repository:",
  641. Value: p.Repository.FullName,
  642. },
  643. {
  644. Name: "Tag:",
  645. Value: p.Release.TagName,
  646. },
  647. },
  648. },
  649. },
  650. PotentialAction: []MSTeamsAction{
  651. {
  652. Type: "OpenUri",
  653. Name: "View in Gitea",
  654. Targets: []MSTeamsActionTarget{
  655. {
  656. Os: "default",
  657. URI: url,
  658. },
  659. },
  660. },
  661. },
  662. }, nil
  663. }
  664. // GetMSTeamsPayload converts a MSTeams webhook into a MSTeamsPayload
  665. func GetMSTeamsPayload(p api.Payloader, event HookEventType, meta string) (*MSTeamsPayload, error) {
  666. s := new(MSTeamsPayload)
  667. switch event {
  668. case HookEventCreate:
  669. return getMSTeamsCreatePayload(p.(*api.CreatePayload))
  670. case HookEventDelete:
  671. return getMSTeamsDeletePayload(p.(*api.DeletePayload))
  672. case HookEventFork:
  673. return getMSTeamsForkPayload(p.(*api.ForkPayload))
  674. case HookEventIssues:
  675. return getMSTeamsIssuesPayload(p.(*api.IssuePayload))
  676. case HookEventIssueComment:
  677. return getMSTeamsIssueCommentPayload(p.(*api.IssueCommentPayload))
  678. case HookEventPush:
  679. return getMSTeamsPushPayload(p.(*api.PushPayload))
  680. case HookEventPullRequest:
  681. return getMSTeamsPullRequestPayload(p.(*api.PullRequestPayload))
  682. case HookEventPullRequestRejected, HookEventPullRequestApproved, HookEventPullRequestComment:
  683. return getMSTeamsPullRequestApprovalPayload(p.(*api.PullRequestPayload), event)
  684. case HookEventRepository:
  685. return getMSTeamsRepositoryPayload(p.(*api.RepositoryPayload))
  686. case HookEventRelease:
  687. return getMSTeamsReleasePayload(p.(*api.ReleasePayload))
  688. }
  689. return s, nil
  690. }
上海开阖软件有限公司 沪ICP备12045867号-1