11#![ allow( dead_code) ]
2+ //! Action module for defining and handling the GitHub Action's inputs, outputs, and core functionality
3+ //!
4+ //! This module contains the Action struct which represents the GitHub Action and implements
5+ //! the necessary functionality to process inputs, validate configurations, and manage outputs.
26use std:: path:: PathBuf ;
37
48use anyhow:: { Context , Result } ;
59use ghactions:: prelude:: * ;
610use ghactions_core:: repository:: reference:: RepositoryReference as Repository ;
711use ghastoolkit:: { CodeQL , CodeQLPack , codeql:: CodeQLLanguage } ;
812
13+ /// ASCII art banner for the CodeQL Extractor Action
914pub const BANNER : & str = r#" ___ _ ____ __ __ _ _ _
1015 / __\___ __| | ___ /___ \/ / /__\_ _| |_ /_\ ___| |_
1116 / / / _ \ / _` |/ _ \// / / / /_\ \ \/ / __|//_\\ / __| __|
1217/ /__| (_) | (_| | __/ \_/ / /___//__ > <| |_/ _ \ (__| |_
1318\____/\___/ \__,_|\___\___,_\____/\__/ /_/\_\\__\_/ \_/\___|\__|"# ;
19+
20+ /// Version of the CodeQL Extractor Action, pulled from Cargo.toml
1421pub const VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
22+
23+ /// Authors of the CodeQL Extractor Action, pulled from Cargo.toml
1524pub const AUTHORS : & str = env ! ( "CARGO_PKG_AUTHORS" ) ;
1625
1726/// This action is for 3rd party CodeQL extractors to be used in GitHub Actions
@@ -94,6 +103,13 @@ pub struct Action {
94103}
95104
96105impl Action {
106+ /// Returns the working directory for the action
107+ ///
108+ /// If no working directory is provided, the current directory is used.
109+ /// Otherwise, the provided directory is resolved to an absolute path.
110+ ///
111+ /// # Returns
112+ /// - `Result<PathBuf>`: The resolved working directory path
97113 pub fn working_directory ( & self ) -> Result < PathBuf > {
98114 if self . working_directory . is_empty ( ) {
99115 log:: debug!( "No working directory provided, using the current directory" ) ;
@@ -108,8 +124,13 @@ impl Action {
108124 ) )
109125 }
110126
111- /// Gets the repository to use for the extractor. If the repository is not provided,
112- /// it will use the repository that the action is running in.
127+ /// Gets the repository references for the extractors
128+ ///
129+ /// If no extractor repositories are provided, the current repository is used.
130+ /// Otherwise, the provided repositories are parsed into Repository objects.
131+ ///
132+ /// # Returns
133+ /// - `Result<Vec<Repository>>`: A list of parsed repository references
113134 pub fn extractor_repository ( & self ) -> Result < Vec < Repository > > {
114135 if self . extractors . is_empty ( ) {
115136 log:: debug!( "No extractor repository provided, using the current repository" ) ;
@@ -129,13 +150,19 @@ impl Action {
129150 . collect :: < Vec < Repository > > ( ) )
130151 }
131152
153+ /// Returns the list of languages to use for CodeQL analysis.
132154 pub fn languages ( & self ) -> Vec < CodeQLLanguage > {
133155 self . languages
134156 . iter ( )
135157 . map ( |lang| CodeQLLanguage :: from ( lang. as_str ( ) ) )
136158 . collect ( )
137159 }
138160
161+ /// Returns the directory to use for CodeQL operations.
162+ ///
163+ /// # Errors
164+ ///
165+ /// Returns an error if the directory cannot be created.
139166 pub fn get_codeql_dir ( & self ) -> Result < PathBuf > {
140167 let paths = vec ! [
141168 // Local CodeQL directory in the working directory
@@ -162,6 +189,11 @@ impl Action {
162189 Err ( anyhow:: anyhow!( "Failed to create CodeQL directory" , ) )
163190 }
164191
192+ /// Validates the provided languages against the supported CodeQL languages.
193+ ///
194+ /// # Errors
195+ ///
196+ /// Returns an error if any of the provided languages are not supported.
165197 pub fn validate_languages ( & self , codeql_languages : & Vec < CodeQLLanguage > ) -> Result < ( ) > {
166198 for lang in self . languages ( ) {
167199 let mut supported = false ;
@@ -187,6 +219,9 @@ impl Action {
187219 Ok ( ( ) )
188220 }
189221
222+ /// Returns the CodeQL version to use.
223+ ///
224+ /// If the CodeQL version is not provided, it defaults to "latest".
190225 pub fn codeql_version ( & self ) -> & str {
191226 if self . codeql_version . is_empty ( ) {
192227 log:: debug!( "No CodeQL version provided, using the latest version" ) ;
@@ -195,6 +230,11 @@ impl Action {
195230 & self . codeql_version
196231 }
197232
233+ /// Installs the specified CodeQL packs.
234+ ///
235+ /// # Errors
236+ ///
237+ /// Returns an error if any of the packs cannot be installed.
198238 pub async fn install_packs ( & self , codeql : & CodeQL ) -> Result < ( ) > {
199239 log:: info!( "Installing CodeQL Packs" ) ;
200240 for pack in & self . packs {
@@ -227,10 +267,12 @@ impl Action {
227267 Ok ( ( ) )
228268 }
229269
270+ /// Returns whether attestation is enabled.
230271 pub fn attestation ( & self ) -> bool {
231272 self . attestation
232273 }
233274
275+ /// Returns whether empty databases are allowed.
234276 pub fn allow_empty_database ( & self ) -> bool {
235277 self . allow_empty_database
236278 }
@@ -240,6 +282,12 @@ impl Action {
240282mod tests {
241283 use super :: * ;
242284
285+ /// Helper function to create a test Action instance with predefined values
286+ ///
287+ /// Creates an Action with:
288+ /// - A single extractor repository "owner/repo"
289+ /// - A single language "iac"
290+ /// - Default values for all other fields
243291 fn action ( ) -> Action {
244292 Action {
245293 extractors : vec ! [ "owner/repo" . to_string( ) ] ,
@@ -248,6 +296,11 @@ mod tests {
248296 }
249297 }
250298
299+ /// Test that language validation works correctly
300+ ///
301+ /// Tests two scenarios:
302+ /// 1. When a language is specified that isn't supported by CodeQL (should error)
303+ /// 2. When a language is specified that is supported by CodeQL (should pass)
251304 #[ test]
252305 fn test_validate_languages ( ) {
253306 let action = action ( ) ;
0 commit comments