File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,11 @@ fn app() -> Result<(), Error> {
101
101
tags:: post,
102
102
api:: is_wg_and_teams,
103
103
) ;
104
+ cmds. add_protected (
105
+ "?tags update {key} value..." ,
106
+ tags:: update,
107
+ api:: is_wg_and_teams,
108
+ ) ;
104
109
cmds. add ( "?tag {key}" , tags:: get) ;
105
110
cmds. add ( "?tags" , tags:: get_all) ;
106
111
cmds. help ( "?tags" , "A key value store" , tags:: help) ;
Original file line number Diff line number Diff line change @@ -51,6 +51,38 @@ pub fn post(args: Args) -> Result<(), Error> {
51
51
Ok ( ( ) )
52
52
}
53
53
54
+ /// Update an existing tag.
55
+ pub fn update ( args : Args ) -> Result < ( ) , Error > {
56
+ if api:: is_wg_and_teams ( & args) ? {
57
+ let conn = DB . get ( ) ?;
58
+
59
+ let key = args
60
+ . params
61
+ . get ( "key" )
62
+ . ok_or ( "Unable to retrieve param: key" ) ?;
63
+
64
+ let value = args
65
+ . params
66
+ . get ( "value" )
67
+ . ok_or ( "Unable to retrieve param: value" ) ?;
68
+
69
+ match diesel:: update ( tags:: table. filter ( tags:: key. eq ( key) ) )
70
+ . set ( tags:: value. eq ( value) )
71
+ . execute ( & conn)
72
+ {
73
+ Ok ( _) => args. msg . react ( args. cx , "✅" ) ?,
74
+ Err ( _) => api:: send_reply ( & args, "A database error occurred when updating the tag." ) ?,
75
+ }
76
+ } else {
77
+ api:: send_reply (
78
+ & args,
79
+ "Please reach out to a Rust team/WG member to update a tag." ,
80
+ ) ?;
81
+ }
82
+
83
+ Ok ( ( ) )
84
+ }
85
+
54
86
/// Retrieve a value by key from the tags.
55
87
pub fn get ( args : Args ) -> Result < ( ) , Error > {
56
88
let conn = DB . get ( ) ?;
@@ -97,6 +129,7 @@ pub fn get_all(args: Args) -> Result<(), Error> {
97
129
pub fn help ( args : Args ) -> Result < ( ) , Error > {
98
130
let help_string = "```
99
131
?tags create {key} value... Create a tag. Limited to WG & Teams.
132
+ ?tags update {key} value... Update a tag. Limited to WG & Teams.
100
133
?tags delete {key} Delete a tag. Limited to WG & Teams.
101
134
?tags help This menu.
102
135
?tags Get all the tags.
You can’t perform that action at this time.
0 commit comments