pub async fn convert_and_upload_pdf(&mut self, github: &Github) {
        // Get the rfd repo client.
        let rfd_repo = github.repo(github_org(), "rfd");
        let repo = rfd_repo.get().await.unwrap();

        let mut path = env::temp_dir();
        path.push(format!("pdfcontents{}.adoc", self.number_string));

        let rfd_content = self.content.to_string();

        // Write the contents to a temporary file.
        let mut file = fs::File::create(path.clone()).unwrap();
        file.write_all(rfd_content.as_bytes()).unwrap();

        let file_name = self.get_pdf_filename();
        let rfd_path = format!("/pdfs/{}", file_name);

        let mut branch = self.number_string.to_string();
        if self.link.contains(&format!("/{}/", repo.default_branch)) {
            branch = repo.default_branch.to_string();
        }

        // Create the dir where to save images.
        let temp_dir = env::temp_dir();
        let temp_dir_str = temp_dir.to_str().unwrap();

        // We need to save the images locally as well.
        // This ensures that
        let old_dir = format!("rfd/{}", self.number_string);
        let images = get_images_in_branch(&rfd_repo, &old_dir, &branch).await;
        for image in images {
            // Save the image to our temporary directory.
            let image_path = format!("{}/{}", temp_dir_str.trim_end_matches('/'), image.path.replace(&old_dir, "").trim_start_matches('/'));

            write_file(&PathBuf::from(image_path), from_utf8(&image.content).unwrap_or_default());
        }

        let cmd_output = Command::new("asciidoctor-pdf")
            .current_dir(env::temp_dir())
            .args(&["-o", "-", "-a", "source-highlighter=rouge", path.to_str().unwrap()])
            .output()
            .unwrap();

        if !cmd_output.status.success() {
            println!("[rfdpdf] running asciidoctor failed:");
            stdout().write_all(&cmd_output.stdout).unwrap();
            stderr().write_all(&cmd_output.stderr).unwrap();
            return;
        }

        // Create or update the file in the github repository.
        create_or_update_file_in_github_repo(&rfd_repo, &repo.default_branch, &rfd_path, cmd_output.stdout.clone()).await;

        // Get gsuite token.
        let token = get_gsuite_token("").await;

        // Initialize the Google Drive client.
        let drive_client = GoogleDrive::new(token);

        // Figure out where our directory is.
        // It should be in the shared drive : "Automated Documents"/"rfds"
        let shared_drive = drive_client.get_drive_by_name("Automated Documents").await.unwrap();
        let drive_id = shared_drive.id.to_string();

        // Get the directory by the name.
        let drive_rfd_dir = drive_client.get_file_by_name(&drive_id, "rfds").await.unwrap();
        let parent_id = drive_rfd_dir.get(0).unwrap().id.to_string();

        // Create or update the file in the google_drive.
        let drive_file = drive_client
            .create_or_update_file(&drive_id, &parent_id, &file_name, "application/pdf", &cmd_output.stdout)
            .await
            .unwrap();
        self.pdf_link_google_drive = format!("https://drive.google.com/open?id={}", drive_file.id);

        // Delete our temporary file.
        if path.exists() && !path.is_dir() {
            fs::remove_file(path).unwrap();
        }
    }
/// Convert the RFD content to a PDF and upload the PDF to the /pdfs folder of the RFD
/// repository.
Convert the RFD content to a PDF and upload the PDF to the /pdfs folder of the RFD
repository.
Convert the RFD content to a PDF and upload the PDF to the / pdfs folder of the RFD repository .
pub async fn convert_and_upload_pdf(&mut self, github: &Github) {
        // Get the rfd repo client.
        let rfd_repo = github.repo(github_org(), "rfd");
        let repo = rfd_repo.get().await.unwrap();
        let mut path = env::temp_dir();
        path.push(format!("pdfcontents{}.adoc", self.number_string));
        let rfd_content = self.content.to_string();
        // Write the contents to a temporary file.
        let mut file = fs::File::create(path.clone()).unwrap();
        file.write_all(rfd_content.as_bytes()).unwrap();
        let file_name = self.get_pdf_filename();
        let rfd_path = format!("/pdfs/{}", file_name);
        let mut branch = self.number_string.to_string();
        if self.link.contains(&format!("/{}/", repo.default_branch)) {
            branch = repo.default_branch.to_string();
        }
        // Create the dir where to save images.
        let temp_dir = env::temp_dir();
        let temp_dir_str = temp_dir.to_str().unwrap();
        // We need to save the images locally as well.
        // This ensures that
        let old_dir = format!("rfd/{}", self.number_string);
        let images = get_images_in_branch(&rfd_repo, &old_dir, &branch).await;
        for image in images {
            // Save the image to our temporary directory.
            let image_path = format!("{}/{}", temp_dir_str.trim_end_matches('/'), image.path.replace(&old_dir, "").trim_start_matches('/'));
            write_file(&PathBuf::from(image_path), from_utf8(&image.content).unwrap_or_default());
        }
        let cmd_output = Command::new("asciidoctor-pdf")
            .current_dir(env::temp_dir())
            .args(&["-o", "-", "-a", "source-highlighter=rouge", path.to_str().unwrap()])
            .output()
            .unwrap();
        if !cmd_output.status.success() {
            println!("[rfdpdf] running asciidoctor failed:");
            stdout().write_all(&cmd_output.stdout).unwrap();
            stderr().write_all(&cmd_output.stderr).unwrap();
            return;
        }
        // Create or update the file in the github repository.
        create_or_update_file_in_github_repo(&rfd_repo, &repo.default_branch, &rfd_path, cmd_output.stdout.clone()).await;
        // Get gsuite token.
        let token = get_gsuite_token("").await;
        // Initialize the Google Drive client.
        let drive_client = GoogleDrive::new(token);
        // Figure out where our directory is.
        // It should be in the shared drive : "Automated Documents"/"rfds"
        let shared_drive = drive_client.get_drive_by_name("Automated Documents").await.unwrap();
        let drive_id = shared_drive.id.to_string();
        // Get the directory by the name.
        let drive_rfd_dir = drive_client.get_file_by_name(&drive_id, "rfds").await.unwrap();
        let parent_id = drive_rfd_dir.get(0).unwrap().id.to_string();
        // Create or update the file in the google_drive.
        let drive_file = drive_client
            .create_or_update_file(&drive_id, &parent_id, &file_name, "application/pdf", &cmd_output.stdout)
            .await
            .unwrap();
        self.pdf_link_google_drive = format!("https://drive.google.com/open?id={}", drive_file.id);
        // Delete our temporary file.
        if path.exists() && !path.is_dir() {
            fs::remove_file(path).unwrap();
        }
    }
pub async fn convert_and_upload_pdf ( & mut self , github : & Github ) { // Get the rfd repo client. let rfd_repo = github . repo ( github_org ( ) , " " ) ; let repo = rfd_repo . get ( ) . await . unwrap ( ) ; let mut path = env :: temp_dir ( ) ; path . push ( format ! ( " " self number_string ) ) ; let rfd_content = self . content . to_string ( ) ; // Write the contents to a temporary file. let mut file = fs :: File :: create ( path . clone ( ) ) . unwrap ( ) ; file . write_all ( rfd_content . as_bytes ( ) ) . unwrap ( ) ; let file_name = self . get_pdf_filename ( ) ; let rfd_path = format ! ( " " file_name ) ; let mut branch = self . number_string . to_string ( ) ; if self . link . contains ( & format ! ( " " repo default_branch ) ) { branch = repo . default_branch . to_string ( ) ; } // Create the dir where to save images. let temp_dir = env :: temp_dir ( ) ; let temp_dir_str = temp_dir . to_str ( ) . unwrap ( ) ; // We need to save the images locally as well. // This ensures that let old_dir = format ! ( " " self number_string ) ; let images = get_images_in_branch ( & rfd_repo , & old_dir , & branch ) . await ; for image in images { // Save the image to our temporary directory. let image_path = format ! ( " " temp_dir_str trim_end_matches ( '/' ) image path replace ( old_dir " " ) trim_start_matches ( '/' ) ) ; write_file ( & PathBuf :: from ( image_path ) , from_utf8 ( & image . content ) . unwrap_or_default ( ) ) ; } let cmd_output = Command :: new ( " " ) . current_dir ( env :: temp_dir ( ) ) . args ( & [ " " , " " , " " , " " , path . to_str ( ) . unwrap ( ) ] ) . output ( ) . unwrap ( ) ; if ! cmd_output . status . success ( ) { println ! ( " " ) ; stdout ( ) . write_all ( & cmd_output . stdout ) . unwrap ( ) ; stderr ( ) . write_all ( & cmd_output . stderr ) . unwrap ( ) ; return ; } // Create or update the file in the github repository. create_or_update_file_in_github_repo ( & rfd_repo , & repo . default_branch , & rfd_path , cmd_output . stdout . clone ( ) ) . await ; // Get gsuite token. let token = get_gsuite_token ( " " ) . await ; // Initialize the Google Drive client. let drive_client = GoogleDrive :: new ( token ) ; // Figure out where our directory is. // It should be in the shared drive : "Automated Documents"/"rfds" let shared_drive = drive_client . get_drive_by_name ( " " ) . await . unwrap ( ) ; let drive_id = shared_drive . id . to_string ( ) ; // Get the directory by the name. let drive_rfd_dir = drive_client . get_file_by_name ( & drive_id , " " ) . await . unwrap ( ) ; let parent_id = drive_rfd_dir . get ( 0 ) . unwrap ( ) . id . to_string ( ) ; // Create or update the file in the google_drive. let drive_file = drive_client . create_or_update_file ( & drive_id , & parent_id , & file_name , " " , & cmd_output . stdout ) . await . unwrap ( ) ; self . pdf_link_google_drive = format ! ( " " drive_file id ) ; // Delete our temporary file. if path . exists ( ) && ! path . is_dir ( ) { fs :: remove_file ( path ) . unwrap ( ) ; } }
Convert the RFD content to a PDF and upload the PDF to the /pdfs folder of the RFD
repository.
Convert the RFD content to a PDF and upload the PDF to the / pdfs folder of the RFD repository .
&mut self
github
&Github
&mut self
github
&Github