lib.rs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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::QueryVariables, Debug, Clone)]
  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. variables = "LeastRecentlyReviewedPullRequestsArguments"
  20. )]
  21. pub struct LeastRecentlyReviewedPullRequests {
  22. #[arguments(owner: $repository_owner, name: $repository_name)]
  23. pub repository: Option<Repository>,
  24. }
  25. #[derive(cynic::QueryFragment, Debug)]
  26. #[cynic(variables = "LeastRecentlyReviewedPullRequestsArguments")]
  27. pub struct Repository {
  28. #[arguments(
  29. states: "OPEN",
  30. first: 100,
  31. after: $after,
  32. labels: ["S-waiting-on-review"],
  33. orderBy: {direction: "ASC", field: "UPDATED_AT"}
  34. )]
  35. pub pull_requests: PullRequestConnection,
  36. }
  37. #[derive(cynic::QueryFragment, Debug)]
  38. pub struct PullRequestConnection {
  39. pub total_count: i32,
  40. pub page_info: PageInfo,
  41. #[cynic(flatten)]
  42. pub nodes: Vec<PullRequest>,
  43. }
  44. #[derive(cynic::QueryFragment, Debug)]
  45. pub struct PullRequest {
  46. pub number: i32,
  47. pub created_at: DateTime,
  48. pub url: Uri,
  49. pub title: String,
  50. #[arguments(first = 100)]
  51. pub labels: Option<LabelConnection>,
  52. pub is_draft: bool,
  53. #[arguments(first = 100)]
  54. pub assignees: UserConnection,
  55. #[arguments(first = 100, orderBy: { direction: "DESC", field: "UPDATED_AT" })]
  56. pub comments: IssueCommentConnection,
  57. #[arguments(last = 20)]
  58. pub latest_reviews: Option<PullRequestReviewConnection>,
  59. }
  60. #[derive(cynic::QueryFragment, Debug)]
  61. pub struct PullRequestReviewConnection {
  62. pub total_count: i32,
  63. #[cynic(flatten)]
  64. pub nodes: Vec<PullRequestReview>,
  65. }
  66. #[derive(cynic::QueryFragment, Debug)]
  67. pub struct PullRequestReview {
  68. pub author: Option<Actor>,
  69. pub created_at: DateTime,
  70. }
  71. #[derive(cynic::QueryFragment, Debug)]
  72. pub struct UserConnection {
  73. #[cynic(flatten)]
  74. pub nodes: Vec<User>,
  75. }
  76. #[derive(cynic::QueryFragment, Debug)]
  77. pub struct User {
  78. pub login: String,
  79. }
  80. #[derive(cynic::QueryFragment, Debug)]
  81. pub struct PageInfo {
  82. pub has_next_page: bool,
  83. pub end_cursor: Option<String>,
  84. }
  85. #[derive(cynic::QueryFragment, Debug)]
  86. pub struct LabelConnection {
  87. #[cynic(flatten)]
  88. pub nodes: Vec<Label>,
  89. }
  90. #[derive(cynic::QueryFragment, Debug)]
  91. pub struct Label {
  92. pub name: String,
  93. }
  94. #[derive(cynic::QueryFragment, Debug)]
  95. pub struct IssueCommentConnection {
  96. pub total_count: i32,
  97. #[cynic(flatten)]
  98. pub nodes: Vec<IssueComment>,
  99. }
  100. #[derive(cynic::QueryFragment, Debug)]
  101. pub struct IssueComment {
  102. pub author: Option<Actor>,
  103. pub created_at: DateTime,
  104. }
  105. #[derive(cynic::QueryFragment, Debug)]
  106. pub struct Actor {
  107. pub login: String,
  108. }
  109. #[derive(cynic::Scalar, Debug, Clone)]
  110. #[cynic(graphql_type = "URI")]
  111. pub struct Uri(pub String);
  112. }
  113. #[cynic::schema_for_derives(file = "src/github.graphql", module = "schema")]
  114. pub mod docs_update_queries {
  115. use super::queries::{DateTime, PageInfo};
  116. use super::schema;
  117. #[derive(cynic::QueryVariables, Clone, Debug)]
  118. pub struct RecentCommitsArguments {
  119. pub branch: String,
  120. pub name: String,
  121. pub owner: String,
  122. pub after: Option<String>,
  123. }
  124. /// Query for fetching recent commits and their associated PRs.
  125. ///
  126. /// This query is built from:
  127. ///
  128. /// ```text
  129. /// query RecentCommits($name: String!, $owner: String!, $branch: String!, $after: String) {
  130. /// repository(name: $name, owner: $owner) {
  131. /// ref(qualifiedName: $branch) {
  132. /// target {
  133. /// ... on Commit {
  134. /// history(first: 100, after: $after) {
  135. /// totalCount
  136. /// pageInfo {
  137. /// hasNextPage
  138. /// endCursor
  139. /// }
  140. /// nodes {
  141. /// oid
  142. /// parents(first: 1) {
  143. /// nodes {
  144. /// oid
  145. /// }
  146. /// }
  147. /// committedDate
  148. /// messageHeadline
  149. /// associatedPullRequests(first: 1) {
  150. /// nodes {
  151. /// number
  152. /// title
  153. /// }
  154. /// }
  155. /// }
  156. /// }
  157. /// }
  158. /// }
  159. /// }
  160. /// }
  161. /// }
  162. /// ```
  163. #[derive(cynic::QueryFragment, Debug)]
  164. #[cynic(graphql_type = "Query", variables = "RecentCommitsArguments")]
  165. pub struct RecentCommits {
  166. #[arguments(name: $name, owner: $owner)]
  167. pub repository: Option<Repository>,
  168. }
  169. #[derive(cynic::QueryFragment, Debug)]
  170. #[cynic(variables = "RecentCommitsArguments")]
  171. pub struct Repository {
  172. #[arguments(qualifiedName: $branch)]
  173. #[cynic(rename = "ref")]
  174. pub ref_: Option<Ref>,
  175. }
  176. #[derive(cynic::QueryFragment, Debug)]
  177. #[cynic(variables = "RecentCommitsArguments")]
  178. pub struct Ref {
  179. pub target: Option<GitObject>,
  180. }
  181. #[derive(cynic::QueryFragment, Debug)]
  182. #[cynic(variables = "RecentCommitsArguments")]
  183. pub struct Commit {
  184. #[arguments(first: 100, after: $after)]
  185. pub history: CommitHistoryConnection,
  186. }
  187. #[derive(cynic::QueryFragment, Debug)]
  188. pub struct CommitHistoryConnection {
  189. pub total_count: i32,
  190. pub page_info: PageInfo,
  191. #[cynic(flatten)]
  192. pub nodes: Vec<Commit2>,
  193. }
  194. #[derive(cynic::QueryFragment, Debug)]
  195. #[cynic(graphql_type = "Commit")]
  196. pub struct Commit2 {
  197. pub oid: GitObjectID,
  198. #[arguments(first = 1)]
  199. pub parents: CommitConnection,
  200. pub committed_date: DateTime,
  201. pub message_headline: String,
  202. #[arguments(first = 1)]
  203. pub associated_pull_requests: Option<PullRequestConnection>,
  204. }
  205. #[derive(cynic::QueryFragment, Debug)]
  206. pub struct PullRequestConnection {
  207. #[cynic(flatten)]
  208. pub nodes: Vec<PullRequest>,
  209. }
  210. #[derive(cynic::QueryFragment, Debug)]
  211. pub struct PullRequest {
  212. pub number: i32,
  213. pub title: String,
  214. }
  215. #[derive(cynic::QueryFragment, Debug)]
  216. pub struct CommitConnection {
  217. #[cynic(flatten)]
  218. pub nodes: Vec<Commit3>,
  219. }
  220. #[derive(cynic::QueryFragment, Debug)]
  221. #[cynic(graphql_type = "Commit")]
  222. pub struct Commit3 {
  223. pub oid: GitObjectID,
  224. }
  225. #[derive(cynic::InlineFragments, Debug)]
  226. #[cynic(variables = "RecentCommitsArguments")]
  227. pub enum GitObject {
  228. Commit(Commit),
  229. #[cynic(fallback)]
  230. Other,
  231. }
  232. #[derive(cynic::Scalar, Debug, Clone)]
  233. pub struct GitObjectID(pub String);
  234. }
  235. #[allow(non_snake_case, non_camel_case_types)]
  236. mod schema {
  237. cynic::use_schema!("src/github.graphql");
  238. }