gitea_rust_sdk/
utils.rs

1use std::fs;
2
3/// Read the gitea api token from the `rsc/gitea_api_token.txt` file and return it as a string.
4pub fn get_token() -> String
5{
6    let token = read_file("rsc/gitea_api_token.txt".to_owned()).replace("\n", "");
7
8    if token == "<PUT YOUR TOKEN HERE>"
9    {
10        println!("Please enter you gitea api token to the 'rsc/gitea_api_token.txt' file.");
11        println!("You can create a token at this url: https://<YOUR GITEA INSTANCE>/user/settings/applications\nE.g.: https://codeberg.org/user/settings/applications");
12        std::process::exit(1);
13    }
14
15    return token;
16}
17
18/// Read the gitea instance url from the `rsc/gitea_instance_url.txt` file and return it as a string.
19pub fn get_url() -> String
20{
21    let url = read_file("rsc/gitea_instance_url.txt".to_owned()).replace("\n", "");
22
23    if url == "<PUT YOUR INSTANCE URL HERE>"
24    {
25        println!("Please enter you gitea instance url to the 'rsc/gitea_instance_url.txt' file.");
26        println!("E.g.: https://codeberg.org");
27        std::process::exit(1);
28    }
29
30    return url;
31}
32
33/// Read the content of a given file and return it as a string.
34fn read_file(path: String) -> String
35{
36    return fs::read_to_string(path).expect("Should have been able to read the file");
37}
38