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

EventExtensions.cs 1.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) Microsoft. All rights reserved.
  2. using System.Globalization;
  3. using Agents;
  4. namespace DevTeam;
  5. public static class EventExtensions
  6. {
  7. public static GithubContext ToGithubContext(this Event evt)
  8. {
  9. ArgumentNullException.ThrowIfNull(evt);
  10. var data = new Dictionary<string, string>();// JsonSerializer.Deserialize<Dictionary<string,string>>(evt.Data);
  11. return new GithubContext
  12. {
  13. Org = data?["org"] ?? "",
  14. Repo = data?["repo"] ?? "",
  15. IssueNumber = data?.TryParseLong("issueNumber") ?? default,
  16. ParentNumber = data?.TryParseLong("parentNumber")
  17. };
  18. }
  19. public static Dictionary<string, string> ToData(this Event evt)
  20. {
  21. ArgumentNullException.ThrowIfNull(evt);
  22. return //JsonSerializer.Deserialize<Dictionary<string,string>>(evt.Data) ??
  23. new Dictionary<string, string>();
  24. }
  25. public static Dictionary<string, string> ToData(this GithubContext context)
  26. {
  27. ArgumentNullException.ThrowIfNull(context);
  28. return new Dictionary<string, string> {
  29. { "org", context.Org },
  30. { "repo", context.Repo },
  31. { "issueNumber", $"{context.IssueNumber}" },
  32. { "parentNumber", context.ParentNumber?.ToString(CultureInfo.InvariantCulture) ?? "" }
  33. };
  34. }
  35. }
  36. public class GithubContext
  37. {
  38. public required string Org { get; set; }
  39. public required string Repo { get; set; }
  40. public long IssueNumber { get; set; }
  41. public long? ParentNumber { get; set; }
  42. public string Subject => $"{Org}/{Repo}/{IssueNumber}";
  43. }