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.7 kB

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