lib.rs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. //! Definitions for GitHub GraphQL.
  2. //!
  3. //! See <https://docs.github.com/en/graphql> for more GitHub's GraphQL API.
  4. // This schema can be downloaded from https://docs.github.com/public/schema.docs.graphql
  5. #[cynic::schema_for_derives(file = "src/github.graphql", module = "schema")]
  6. pub mod queries {
  7. use super::schema;
  8. pub type DateTime = chrono::DateTime<chrono::Utc>;
  9. cynic::impl_scalar!(DateTime, schema::DateTime);
  10. #[derive(cynic::FragmentArguments, Debug)]
  11. pub struct LeastRecentlyReviewedPullRequestsArguments {
  12. pub repository_owner: String,
  13. pub repository_name: String,
  14. pub after: Option<String>,
  15. }
  16. #[derive(cynic::QueryFragment, Debug)]
  17. #[cynic(
  18. graphql_type = "Query",
  19. argument_struct = "LeastRecentlyReviewedPullRequestsArguments"
  20. )]
  21. pub struct LeastRecentlyReviewedPullRequests {
  22. #[arguments(owner = &args.repository_owner, name = &args.repository_name)]
  23. pub repository: Option<Repository>,
  24. }
  25. #[derive(cynic::QueryFragment, Debug)]
  26. #[cynic(argument_struct = "LeastRecentlyReviewedPullRequestsArguments")]
  27. pub struct Repository {
  28. #[arguments(states = Some(vec![PullRequestState::Open]), first = 100, after = &args.after, labels = Some(vec!["S-waiting-on-review".to_string()]), order_by = IssueOrder { direction: OrderDirection::Asc, field: IssueOrderField::UpdatedAt })]
  29. pub pull_requests: PullRequestConnection,
  30. }
  31. #[derive(cynic::QueryFragment, Debug)]
  32. pub struct PullRequestConnection {
  33. pub total_count: i32,
  34. pub page_info: PageInfo,
  35. pub nodes: Option<Vec<Option<PullRequest>>>,
  36. }
  37. #[derive(cynic::QueryFragment, Debug)]
  38. pub struct PullRequest {
  39. pub number: i32,
  40. pub created_at: DateTime,
  41. pub url: Uri,
  42. pub title: String,
  43. #[arguments(first = 100)]
  44. pub labels: Option<LabelConnection>,
  45. pub is_draft: bool,
  46. #[arguments(first = 100)]
  47. pub assignees: UserConnection,
  48. #[arguments(first = 100, order_by = IssueCommentOrder { direction: OrderDirection::Desc, field: IssueCommentOrderField::UpdatedAt })]
  49. pub comments: IssueCommentConnection,
  50. #[arguments(last = 20)]
  51. pub latest_reviews: Option<PullRequestReviewConnection>,
  52. }
  53. #[derive(cynic::QueryFragment, Debug)]
  54. pub struct PullRequestReviewConnection {
  55. pub total_count: i32,
  56. pub nodes: Option<Vec<Option<PullRequestReview>>>,
  57. }
  58. #[derive(cynic::QueryFragment, Debug)]
  59. pub struct PullRequestReview {
  60. pub author: Option<Actor>,
  61. pub created_at: DateTime,
  62. }
  63. #[derive(cynic::QueryFragment, Debug)]
  64. pub struct UserConnection {
  65. pub nodes: Option<Vec<Option<User>>>,
  66. }
  67. #[derive(cynic::QueryFragment, Debug)]
  68. pub struct User {
  69. pub login: String,
  70. }
  71. #[derive(cynic::QueryFragment, Debug)]
  72. pub struct PageInfo {
  73. pub has_next_page: bool,
  74. pub end_cursor: Option<String>,
  75. }
  76. #[derive(cynic::QueryFragment, Debug)]
  77. pub struct LabelConnection {
  78. pub nodes: Option<Vec<Option<Label>>>,
  79. }
  80. #[derive(cynic::QueryFragment, Debug)]
  81. pub struct Label {
  82. pub name: String,
  83. }
  84. #[derive(cynic::QueryFragment, Debug)]
  85. pub struct IssueCommentConnection {
  86. pub total_count: i32,
  87. pub nodes: Option<Vec<Option<IssueComment>>>,
  88. }
  89. #[derive(cynic::QueryFragment, Debug)]
  90. pub struct IssueComment {
  91. pub author: Option<Actor>,
  92. pub created_at: DateTime,
  93. }
  94. #[derive(cynic::Enum, Clone, Copy, Debug)]
  95. pub enum IssueCommentOrderField {
  96. UpdatedAt,
  97. }
  98. #[derive(cynic::Enum, Clone, Copy, Debug)]
  99. pub enum IssueOrderField {
  100. Comments,
  101. CreatedAt,
  102. UpdatedAt,
  103. }
  104. #[derive(cynic::Enum, Clone, Copy, Debug)]
  105. pub enum OrderDirection {
  106. Asc,
  107. Desc,
  108. }
  109. #[derive(cynic::Enum, Clone, Copy, Debug)]
  110. pub enum PullRequestState {
  111. Closed,
  112. Merged,
  113. Open,
  114. }
  115. #[derive(cynic::InputObject, Debug)]
  116. pub struct IssueOrder {
  117. pub direction: OrderDirection,
  118. pub field: IssueOrderField,
  119. }
  120. #[derive(cynic::InputObject, Debug)]
  121. pub struct IssueCommentOrder {
  122. pub direction: OrderDirection,
  123. pub field: IssueCommentOrderField,
  124. }
  125. #[derive(cynic::QueryFragment, Debug)]
  126. pub struct Actor {
  127. pub login: String,
  128. }
  129. #[derive(cynic::Scalar, Debug, Clone)]
  130. pub struct Uri(pub String);
  131. }
  132. #[cynic::schema_for_derives(file = "src/github.graphql", module = "schema")]
  133. pub mod docs_update_queries {
  134. use super::queries::{DateTime, PageInfo};
  135. use super::schema;
  136. #[derive(cynic::FragmentArguments, Debug)]
  137. pub struct RecentCommitsArguments {
  138. pub branch: String,
  139. pub name: String,
  140. pub owner: String,
  141. pub after: Option<String>,
  142. }
  143. #[derive(cynic::QueryFragment, Debug)]
  144. #[cynic(graphql_type = "Query", argument_struct = "RecentCommitsArguments")]
  145. pub struct RecentCommits {
  146. #[arguments(name = &args.name, owner = &args.owner)]
  147. pub repository: Option<Repository>,
  148. }
  149. #[derive(cynic::QueryFragment, Debug)]
  150. #[cynic(argument_struct = "RecentCommitsArguments")]
  151. pub struct Repository {
  152. #[arguments(qualified_name = &args.branch)]
  153. #[cynic(rename = "ref")]
  154. pub ref_: Option<Ref>,
  155. }
  156. #[derive(cynic::QueryFragment, Debug)]
  157. pub struct Ref {
  158. pub target: Option<GitObject>,
  159. }
  160. #[derive(cynic::QueryFragment, Debug)]
  161. pub struct Commit {
  162. #[arguments(first = 100)]
  163. pub history: CommitHistoryConnection,
  164. }
  165. #[derive(cynic::QueryFragment, Debug)]
  166. pub struct CommitHistoryConnection {
  167. pub total_count: i32,
  168. pub page_info: PageInfo,
  169. pub nodes: Option<Vec<Option<Commit2>>>,
  170. }
  171. #[derive(cynic::QueryFragment, Debug)]
  172. #[cynic(graphql_type = "Commit")]
  173. pub struct Commit2 {
  174. pub oid: GitObjectID,
  175. #[arguments(first = 1)]
  176. pub parents: CommitConnection,
  177. pub committed_date: DateTime,
  178. pub message_headline: String,
  179. #[arguments(first = 1)]
  180. pub associated_pull_requests: Option<PullRequestConnection>,
  181. }
  182. #[derive(cynic::QueryFragment, Debug)]
  183. pub struct PullRequestConnection {
  184. pub nodes: Option<Vec<Option<PullRequest>>>,
  185. }
  186. #[derive(cynic::QueryFragment, Debug)]
  187. pub struct PullRequest {
  188. pub number: i32,
  189. pub title: String,
  190. }
  191. #[derive(cynic::QueryFragment, Debug)]
  192. pub struct CommitConnection {
  193. pub nodes: Option<Vec<Option<Commit3>>>,
  194. }
  195. #[derive(cynic::QueryFragment, Debug)]
  196. #[cynic(graphql_type = "Commit")]
  197. pub struct Commit3 {
  198. pub oid: GitObjectID,
  199. }
  200. #[derive(cynic::InlineFragments, Debug)]
  201. pub enum GitObject {
  202. Commit(Commit),
  203. // These three variants are here just to pacify cynic. I don't know
  204. // why it fails to compile without them.
  205. Tree(Tree),
  206. Tag(Tag),
  207. Blob(Blob),
  208. }
  209. #[derive(cynic::QueryFragment, Debug)]
  210. pub struct Tree {
  211. pub id: cynic::Id,
  212. }
  213. #[derive(cynic::QueryFragment, Debug)]
  214. pub struct Tag {
  215. pub id: cynic::Id,
  216. }
  217. #[derive(cynic::QueryFragment, Debug)]
  218. pub struct Blob {
  219. pub id: cynic::Id,
  220. }
  221. #[derive(cynic::Scalar, Debug, Clone)]
  222. pub struct GitObjectID(pub String);
  223. }
  224. mod schema {
  225. cynic::use_schema!("src/github.graphql");
  226. }