@@ -877,6 +877,63 @@ impl Issue {
877
877
) ) ;
878
878
Ok ( client. json ( req) . await ?)
879
879
}
880
+
881
+ /// Returns the GraphQL ID of this issue.
882
+ async fn graphql_issue_id ( & self , client : & GithubClient ) -> anyhow:: Result < String > {
883
+ let repo = self . repository ( ) ;
884
+ let mut issue_id = client
885
+ . graphql_query (
886
+ "query($owner:String!, $repo:String!, $issueNum:Int!) {
887
+ repository(owner: $owner, name: $repo) {
888
+ issue(number: $issueNum) {
889
+ id
890
+ }
891
+ }
892
+ }
893
+ " ,
894
+ serde_json:: json!( {
895
+ "owner" : repo. organization,
896
+ "repo" : repo. repository,
897
+ "issueNum" : self . number,
898
+ } ) ,
899
+ )
900
+ . await ?;
901
+ let serde_json:: Value :: String ( issue_id) =
902
+ issue_id[ "data" ] [ "repository" ] [ "issue" ] [ "id" ] . take ( )
903
+ else {
904
+ anyhow:: bail!( "expected issue id, got {issue_id}" ) ;
905
+ } ;
906
+ Ok ( issue_id)
907
+ }
908
+
909
+ /// Transfers this issue to the given repository.
910
+ pub async fn transfer (
911
+ & self ,
912
+ client : & GithubClient ,
913
+ owner : & str ,
914
+ repo : & str ,
915
+ ) -> anyhow:: Result < ( ) > {
916
+ let issue_id = self . graphql_issue_id ( client) . await ?;
917
+ let repo_id = client. graphql_repo_id ( owner, repo) . await ?;
918
+ client
919
+ . graphql_query (
920
+ "mutation ($issueId: ID!, $repoId: ID!) {
921
+ transferIssue(
922
+ input: {createLabelsIfMissing: true, issueId: $issueId, repositoryId: $repoId}
923
+ ) {
924
+ issue {
925
+ id
926
+ }
927
+ }
928
+ }" ,
929
+ serde_json:: json!( {
930
+ "issueId" : issue_id,
931
+ "repoId" : repo_id,
932
+ } ) ,
933
+ )
934
+ . await ?;
935
+ Ok ( ( ) )
936
+ }
880
937
}
881
938
882
939
#[ derive( Debug , serde:: Deserialize ) ]
@@ -2424,6 +2481,27 @@ impl GithubClient {
2424
2481
. with_context ( || format ! ( "failed to set milestone for {url} to milestone {milestone:?}" ) ) ?;
2425
2482
Ok ( ( ) )
2426
2483
}
2484
+
2485
+ /// Returns the GraphQL ID of the given repository.
2486
+ async fn graphql_repo_id ( & self , owner : & str , repo : & str ) -> anyhow:: Result < String > {
2487
+ let mut repo_id = self
2488
+ . graphql_query (
2489
+ "query($owner:String!, $repo:String!) {
2490
+ repository(owner: $owner, name: $repo) {
2491
+ id
2492
+ }
2493
+ }" ,
2494
+ serde_json:: json!( {
2495
+ "owner" : owner,
2496
+ "repo" : repo,
2497
+ } ) ,
2498
+ )
2499
+ . await ?;
2500
+ let serde_json:: Value :: String ( repo_id) = repo_id[ "data" ] [ "repository" ] [ "id" ] . take ( ) else {
2501
+ anyhow:: bail!( "expected repo id, got {repo_id}" ) ;
2502
+ } ;
2503
+ Ok ( repo_id)
2504
+ }
2427
2505
}
2428
2506
2429
2507
#[ derive( Debug , serde:: Deserialize ) ]
0 commit comments