File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed
Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ v0.6.0 (in development)
1616- Added ` GHRepo::as_str() ` method
1717- ** Breaking** : The ` GHRepo::is_valid_owner() ` and ` GHRepo::is_valid_name() `
1818 methods are now regular functions
19+ - Added ` is_valid_repository() ` function
1920
2021v0.5.0 (2023-04-27)
2122-------------------
Original file line number Diff line number Diff line change @@ -678,3 +678,18 @@ pub fn is_valid_owner(s: &str) -> bool {
678678pub fn is_valid_name ( s : & str ) -> bool {
679679 matches ! ( split_name( s) , Some ( ( _, "" ) ) )
680680}
681+
682+ /// Test whether a string is a valid repository specifier/full name of the form
683+ /// `{owner}/{name}`.
684+ ///
685+ /// # Example
686+ ///
687+ /// ```
688+ /// # use ghrepo::is_valid_repository;
689+ /// assert!(is_valid_repository("octocat/my-repo"));
690+ /// assert!(!is_valid_repository("octocat/my-repo.git"));
691+ /// assert!(!is_valid_repository("my-repo"));
692+ /// ```
693+ pub fn is_valid_repository ( s : & str ) -> bool {
694+ matches ! ( split_owner_name( s) , Some ( ( _, _, "" ) ) )
695+ }
Original file line number Diff line number Diff line change 11#![ allow( clippy:: items_after_test_module) ]
2- use ghrepo:: { is_valid_name, is_valid_owner} ;
2+ use ghrepo:: { is_valid_name, is_valid_owner, is_valid_repository } ;
33use rstest:: rstest;
44
55#[ rstest]
@@ -37,6 +37,7 @@ fn test_good_owner(#[case] owner: &str) {
3737#[ case( "steven.universe" ) ]
3838#[ case( "steven-universe@beachcity.dv" ) ]
3939#[ case( "steven-univerß" ) ]
40+ #[ case( "steven/universe" ) ]
4041#[ case( "" ) ]
4142#[ case( "none" ) ]
4243#[ case( "NONE" ) ]
@@ -90,6 +91,22 @@ fn test_good_name(#[case] name: &str) {
9091#[ case( "steven.git" ) ]
9192#[ case( "steven.GIT" ) ]
9293#[ case( "steven.Git" ) ]
94+ #[ case( "steven/universe" ) ]
9395fn test_bad_name ( #[ case] name : & str ) {
9496 assert ! ( !is_valid_name( name) ) ;
9597}
98+
99+ #[ rstest]
100+ #[ case( "steven/universe" ) ]
101+ fn test_good_repository ( #[ case] spec : & str ) {
102+ assert ! ( is_valid_repository( spec) ) ;
103+ }
104+
105+ #[ rstest]
106+ #[ case( "steven/universe.git" ) ]
107+ #[ case( "steven/universe/main" ) ]
108+ #[ case( "https://github.com/steven/universe" ) ]
109+ #[ case( "steven" ) ]
110+ fn test_bad_repository ( #[ case] spec : & str ) {
111+ assert ! ( !is_valid_repository( spec) ) ;
112+ }
You can’t perform that action at this time.
0 commit comments