Skip to content

Commit

Permalink
version: fix pull request check
Browse files Browse the repository at this point in the history
  • Loading branch information
darakeon committed Aug 24, 2023
1 parent 028407a commit 87689da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions version/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ fn get_path(file: DiffFile) -> String {
return file.path().unwrap().to_str().unwrap().to_string();
}

pub fn has_pull_request() -> bool {
pub fn has_pull_request(version: String) -> bool {
let url_repo = url_repo();
let url_api = url_api(&url_repo);
let url_api = url_api(&url_repo, version);

let client = Client::new().get(&url_api).header("User-Agent", "");
let response = client.send().unwrap();
Expand All @@ -111,14 +111,12 @@ fn url_repo() -> String {
.url().unwrap().to_string();
}

fn url_api(url_repo: &str) -> String {
fn url_api(url_repo: &str, version: String) -> String {
let pattern = r"git@github.com:(\w+)/(\w+).git";
let replacer = r"https://api.github.com/repos/$1/$2/pulls?state=open&head=$1:";
let replaced = replace(url_repo, pattern, replacer).unwrap();

let branch = current_branch().unwrap();

return format!("{}{}", replaced, branch);
return format!("{}{}", replaced, version);
}

pub fn update_local() {
Expand Down
6 changes: 3 additions & 3 deletions version/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn create_version(option: &ProgramOption, numbers: Vec<usize>) -> Option<Ver
}

if !version.done {
return end_not_done();
return end_not_done(version.code);
}

let just_check = option == &ProgramOption::Check;
Expand Down Expand Up @@ -108,8 +108,8 @@ fn start_of_current_tasks(task_list: &Vec<String>, branch: String) -> usize {
return start;
}

fn end_not_done() -> Option<Version> {
if has_pull_request() {
fn end_not_done(version: String) -> Option<Version> {
if has_pull_request(version) {
throw(11, "There is an opened pull request and the version is not done");
}

Expand Down

0 comments on commit 87689da

Please sign in to comment.