@@ -798,3 +798,175 @@ pub struct ArtifactCollection {
798798 pub duration : Duration ,
799799 pub end_time : DateTime < Utc > ,
800800}
801+
802+ #[ derive( Debug ) ]
803+ pub enum BenchmarkRequestStatus {
804+ WaitingForArtifacts ,
805+ WaitingForParent ,
806+ InProgress ,
807+ Completed ,
808+ }
809+
810+ impl fmt:: Display for BenchmarkRequestStatus {
811+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
812+ match self {
813+ BenchmarkRequestStatus :: WaitingForArtifacts => write ! ( f, "waiting_for_artifacts" ) ,
814+ BenchmarkRequestStatus :: WaitingForParent => write ! ( f, "waiting_for_parent" ) ,
815+ BenchmarkRequestStatus :: InProgress => write ! ( f, "in_progress" ) ,
816+ BenchmarkRequestStatus :: Completed => write ! ( f, "completed" ) ,
817+ }
818+ }
819+ }
820+
821+ #[ derive( Debug ) ]
822+ pub enum BenchmarkRequestType {
823+ /// A Try commit
824+ Try {
825+ sha : String ,
826+ parent_sha : String ,
827+ pr : u32 ,
828+ } ,
829+ /// A Master commit
830+ Master {
831+ sha : String ,
832+ parent_sha : String ,
833+ pr : u32 ,
834+ } ,
835+ /// A release only has a tag
836+ Release { tag : String } ,
837+ }
838+
839+ impl BenchmarkRequestType {
840+ pub fn commit_type_str ( & self ) -> & str {
841+ match self {
842+ BenchmarkRequestType :: Try {
843+ sha : _,
844+ parent_sha : _,
845+ pr : _,
846+ } => "try" ,
847+ BenchmarkRequestType :: Master {
848+ sha : _,
849+ parent_sha : _,
850+ pr : _,
851+ } => "master" ,
852+ BenchmarkRequestType :: Release { tag : _ } => "release" ,
853+ }
854+ }
855+ }
856+
857+ impl fmt:: Display for BenchmarkRequestType {
858+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
859+ match self {
860+ BenchmarkRequestType :: Try { .. } => write ! ( f, "try" ) ,
861+ BenchmarkRequestType :: Master { .. } => write ! ( f, "master" ) ,
862+ BenchmarkRequestType :: Release { tag : _ } => write ! ( f, "release" ) ,
863+ }
864+ }
865+ }
866+
867+ #[ derive( Debug ) ]
868+ pub struct BenchmarkRequest {
869+ pub commit_type : BenchmarkRequestType ,
870+ pub created_at : DateTime < Utc > ,
871+ pub completed_at : Option < DateTime < Utc > > ,
872+ pub status : BenchmarkRequestStatus ,
873+ pub backends : String ,
874+ pub profiles : String ,
875+ }
876+
877+ impl BenchmarkRequest {
878+ pub fn create_release (
879+ tag : & str ,
880+ created_at : DateTime < Utc > ,
881+ status : BenchmarkRequestStatus ,
882+ backends : & str ,
883+ profiles : & str ,
884+ ) -> Self {
885+ Self {
886+ commit_type : BenchmarkRequestType :: Release {
887+ tag : tag. to_string ( ) ,
888+ } ,
889+ created_at,
890+ completed_at : None ,
891+ status,
892+ backends : backends. to_string ( ) ,
893+ profiles : profiles. to_string ( ) ,
894+ }
895+ }
896+
897+ pub fn create_try (
898+ sha : & str ,
899+ parent_sha : & str ,
900+ pr : u32 ,
901+ created_at : DateTime < Utc > ,
902+ status : BenchmarkRequestStatus ,
903+ backends : & str ,
904+ profiles : & str ,
905+ ) -> Self {
906+ Self {
907+ commit_type : BenchmarkRequestType :: Try {
908+ pr,
909+ sha : sha. to_string ( ) ,
910+ parent_sha : parent_sha. to_string ( ) ,
911+ } ,
912+ created_at,
913+ completed_at : None ,
914+ status,
915+ backends : backends. to_string ( ) ,
916+ profiles : profiles. to_string ( ) ,
917+ }
918+ }
919+
920+ pub fn create_master (
921+ sha : & str ,
922+ parent_sha : & str ,
923+ pr : u32 ,
924+ created_at : DateTime < Utc > ,
925+ status : BenchmarkRequestStatus ,
926+ backends : & str ,
927+ profiles : & str ,
928+ ) -> Self {
929+ Self {
930+ commit_type : BenchmarkRequestType :: Master {
931+ pr,
932+ sha : sha. to_string ( ) ,
933+ parent_sha : parent_sha. to_string ( ) ,
934+ } ,
935+ created_at,
936+ completed_at : None ,
937+ status,
938+ backends : backends. to_string ( ) ,
939+ profiles : profiles. to_string ( ) ,
940+ }
941+ }
942+
943+ /// Get either the `sha` for a `try` or `master` commit or a `tag` for a
944+ /// `release`
945+ pub fn tag ( & self ) -> & str {
946+ match & self . commit_type {
947+ BenchmarkRequestType :: Try { sha, .. } | BenchmarkRequestType :: Master { sha, .. } => sha,
948+ BenchmarkRequestType :: Release { tag } => tag,
949+ }
950+ }
951+
952+ pub fn pr ( & self ) -> Option < & u32 > {
953+ match & self . commit_type {
954+ BenchmarkRequestType :: Try { pr, .. } | BenchmarkRequestType :: Master { pr, .. } => {
955+ Some ( pr)
956+ }
957+ BenchmarkRequestType :: Release { tag : _ } => None ,
958+ }
959+ }
960+
961+ pub fn commit_type ( & self ) -> & str {
962+ self . commit_type . commit_type_str ( )
963+ }
964+
965+ pub fn parent_sha ( & self ) -> Option < & str > {
966+ match & self . commit_type {
967+ BenchmarkRequestType :: Try { parent_sha, .. }
968+ | BenchmarkRequestType :: Master { parent_sha, .. } => Some ( parent_sha) ,
969+ BenchmarkRequestType :: Release { tag : _ } => None ,
970+ }
971+ }
972+ }
0 commit comments