@@ -129,9 +129,9 @@ impl GHRepo {
129129 /// If `owner` is not a valid GitHub owner name, or if `name` is not a
130130 /// valid GitHub repository name, returns [`ParseError`].
131131 pub fn new ( owner : & str , name : & str ) -> Result < Self , ParseError > {
132- if !GHRepo :: is_valid_owner ( owner) {
132+ if !is_valid_owner ( owner) {
133133 Err ( ParseError :: InvalidOwner ( owner. to_string ( ) ) )
134- } else if !GHRepo :: is_valid_name ( name) {
134+ } else if !is_valid_name ( name) {
135135 Err ( ParseError :: InvalidName ( name. to_string ( ) ) )
136136 } else {
137137 Ok ( GHRepo {
@@ -141,57 +141,6 @@ impl GHRepo {
141141 }
142142 }
143143
144- /// Test whether a string is a valid GitHub user login or organization
145- /// name.
146- ///
147- /// As of 2017-07-23, trying to sign up to GitHub with an invalid username
148- /// or create an organization with an invalid name gives the message
149- /// "Username may only contain alphanumeric characters or single hyphens,
150- /// and cannot begin or end with a hyphen". Additionally, trying to create
151- /// a user named "none" (case insensitive) gives the message "Username name
152- /// 'none' is a reserved word." Unfortunately, there are a number of users
153- /// who made accounts before the current name restrictions were put in
154- /// place, and so this method also needs to accept names that contain
155- /// underscores, contain multiple consecutive hyphens, begin with a hyphen,
156- /// and/or end with a hyphen.
157- ///
158- /// As this function endeavors to accept all usernames that were valid at
159- /// any point, just because a name is accepted doesn't necessarily mean you
160- /// can create a user by that name on GitHub today.
161- ///
162- /// # Example
163- ///
164- /// ```
165- /// # use ghrepo::GHRepo;
166- /// assert!(GHRepo::is_valid_owner("octocat"));
167- /// assert!(GHRepo::is_valid_owner("octo-cat"));
168- /// assert!(!GHRepo::is_valid_owner("octo.cat"));
169- /// assert!(!GHRepo::is_valid_owner("octocat/repository"));
170- /// assert!(!GHRepo::is_valid_owner("none"));
171- /// ```
172- pub fn is_valid_owner ( s : & str ) -> bool {
173- matches ! ( split_owner( s) , Some ( ( _, "" ) ) )
174- }
175-
176- /// Test whether a string is a valid repository name.
177- ///
178- /// Testing as of 2017-05-21 indicates that repository names can be
179- /// composed of alphanumeric ASCII characters, hyphens, periods, and/or
180- /// underscores, with the names `.` and `..` being reserved and names
181- /// ending with `.git` (case insensitive) forbidden.
182- ///
183- /// # Example
184- ///
185- /// ```
186- /// # use ghrepo::GHRepo;
187- /// assert!(GHRepo::is_valid_name("my-repo"));
188- /// assert!(!GHRepo::is_valid_name("my-repo.git"));
189- /// assert!(!GHRepo::is_valid_owner("octocat/my-repo"));
190- /// ```
191- pub fn is_valid_name ( s : & str ) -> bool {
192- matches ! ( split_name( s) , Some ( ( _, "" ) ) )
193- }
194-
195144 /// Like [`GHRepo::from_str()`], except that if `s` is just a repository
196145 /// name without an owner, the owner will be set to `owner`
197146 ///
@@ -217,7 +166,7 @@ impl GHRepo {
217166 /// # }
218167 /// ```
219168 pub fn from_str_with_owner ( s : & str , owner : & str ) -> Result < Self , ParseError > {
220- if GHRepo :: is_valid_name ( s) {
169+ if is_valid_name ( s) {
221170 GHRepo :: new ( owner, s)
222171 } else {
223172 GHRepo :: from_str ( s)
@@ -680,3 +629,52 @@ impl From<ParseError> for LocalRepoError {
680629 LocalRepoError :: InvalidRemoteURL ( e)
681630 }
682631}
632+
633+ /// Test whether a string is a valid GitHub user login or organization name.
634+ ///
635+ /// As of 2017-07-23, trying to sign up to GitHub with an invalid username or
636+ /// create an organization with an invalid name gives the message "Username may
637+ /// only contain alphanumeric characters or single hyphens, and cannot begin or
638+ /// end with a hyphen". Additionally, trying to create a user named "none"
639+ /// (case insensitive) gives the message "Username name 'none' is a reserved
640+ /// word." Unfortunately, there are a number of users who made accounts before
641+ /// the current name restrictions were put in place, and so this method also
642+ /// needs to accept names that contain underscores, contain multiple
643+ /// consecutive hyphens, begin with a hyphen, and/or end with a hyphen.
644+ ///
645+ /// As this function endeavors to accept all usernames that were valid at any
646+ /// point, just because a name is accepted doesn't necessarily mean you can
647+ /// create a user by that name on GitHub today.
648+ ///
649+ /// # Example
650+ ///
651+ /// ```
652+ /// # use ghrepo::is_valid_owner;
653+ /// assert!(is_valid_owner("octocat"));
654+ /// assert!(is_valid_owner("octo-cat"));
655+ /// assert!(!is_valid_owner("octo.cat"));
656+ /// assert!(!is_valid_owner("octocat/repository"));
657+ /// assert!(!is_valid_owner("none"));
658+ /// ```
659+ pub fn is_valid_owner ( s : & str ) -> bool {
660+ matches ! ( split_owner( s) , Some ( ( _, "" ) ) )
661+ }
662+
663+ /// Test whether a string is a valid repository name.
664+ ///
665+ /// Testing as of 2017-05-21 indicates that repository names can be composed of
666+ /// alphanumeric ASCII characters, hyphens, periods, and/or underscores, with
667+ /// the names `.` and `..` being reserved and names ending with `.git` (case
668+ /// insensitive) forbidden.
669+ ///
670+ /// # Example
671+ ///
672+ /// ```
673+ /// # use ghrepo::is_valid_name;
674+ /// assert!(is_valid_name("my-repo"));
675+ /// assert!(!is_valid_name("my-repo.git"));
676+ /// assert!(!is_valid_name("octocat/my-repo"));
677+ /// ```
678+ pub fn is_valid_name ( s : & str ) -> bool {
679+ matches ! ( split_name( s) , Some ( ( _, "" ) ) )
680+ }
0 commit comments