@@ -2,7 +2,7 @@ use crate::dialoguer;
2
2
use anyhow:: Context ;
3
3
use chrono:: { NaiveDateTime , Utc } ;
4
4
use colored:: Colorize ;
5
- use crates_io:: models:: NewDeletedCrate ;
5
+ use crates_io:: models:: { NewDeletedCrate , User } ;
6
6
use crates_io:: schema:: { crate_downloads, deleted_crates} ;
7
7
use crates_io:: worker:: jobs;
8
8
use crates_io:: { db, schema:: crates} ;
@@ -29,6 +29,10 @@ pub struct Opts {
29
29
/// Don't ask for confirmation: yes, we are sure. Best for scripting.
30
30
#[ arg( short, long) ]
31
31
yes : bool ,
32
+
33
+ /// Your GitHub username.
34
+ #[ arg( long) ]
35
+ deleted_by : Option < String > ,
32
36
}
33
37
34
38
pub async fn run ( opts : Opts ) -> anyhow:: Result < ( ) > {
@@ -63,6 +67,8 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> {
63
67
return Ok ( ( ) ) ;
64
68
}
65
69
70
+ let deleted_by = get_deleted_by ( & mut conn, opts. deleted_by . as_deref ( ) ) . await ?;
71
+
66
72
let now = Utc :: now ( ) ;
67
73
68
74
for name in & crate_names {
@@ -73,6 +79,7 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> {
73
79
let deleted_crate = NewDeletedCrate :: builder ( name)
74
80
. created_at ( & created_at)
75
81
. deleted_at ( & now)
82
+ . maybe_deleted_by ( deleted_by)
76
83
. available_at ( & now)
77
84
. build ( ) ;
78
85
@@ -109,6 +116,18 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> {
109
116
Ok ( ( ) )
110
117
}
111
118
119
+ async fn get_deleted_by (
120
+ conn : & mut AsyncPgConnection ,
121
+ deleted_by : Option < & str > ,
122
+ ) -> QueryResult < Option < i32 > > {
123
+ let Some ( deleted_by) = deleted_by else {
124
+ return Ok ( None ) ;
125
+ } ;
126
+
127
+ let user = User :: async_find_by_login ( conn, deleted_by) . await ?;
128
+ Ok ( Some ( user. id ) )
129
+ }
130
+
112
131
async fn delete_from_database (
113
132
conn : & mut AsyncPgConnection ,
114
133
crate_id : i32 ,
0 commit comments