This repository was archived by the owner on May 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 705
[Movey] Add command to upload metadata to Movey #227
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
532531f
upload metadata to movey
ea-open-source e1091b2
Add api token to upload request, get token from credential file
ea-open-source 1213fbe
Show error message if upload with bad credentials
ea-open-source 4c4d756
Refactor move_cli's utils & add cli tests
ea-open-source fe74142
Remove `description, total_size` field from request body, change move…
ea-open-source 3eab134
call movey api after getting dependency
ea-open-source 5b63f9d
Change dev movey_url, send params in post request
ea-open-source cd20142
Refactor error message when upload failed, add reqwest crate
ea-open-source 0d374f6
Get long rev, use cli_exe path from env
ea-open-source c99c9b5
Refactor test code to run in parallel
ea-open-source 38eefef
Refactor tests to run in current dir, flatten `upload` command
ea-open-source b575537
Refactor to be specific to Movey, change UploadRequest's params
ea-open-source 1bdf00d
Refactor MOVE_HOME env, MOVEY_URL to common package
ea-open-source 9f1c462
Refactor test logic in uploading, remove `increase download` logic
ea-open-source ccc39c6
Add Movey server Mock, refactor test code in upload
ea-open-source e98bb73
Rename move_command_line_common::movey.rs to movey_constants.rs
ea-open-source 9680b91
Change movey api url, refactor getting credential key, refactor tests
ea-open-source 41d4298
Rename movey api, change the message of successful upload request
ea-open-source 6fd45f5
Refactor and add comments for movey tests
ea-open-source 190f3a2
Refactor and rebase according to #226 changes
ea-open-source 7a63283
Refactor mock movey server function, remove unnecessary license
ea-open-source e94be27
Move `MOVEY_CREDENTIAL_PATH` to common package, refactor logic of rea…
ea-open-source File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| // Copyright (c) The Move Contributors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use crate::utils::movey_credential; | ||
| use anyhow::bail; | ||
| use clap::*; | ||
| use move_command_line_common::env::MOVE_HOME; | ||
| use reqwest::blocking::Client; | ||
| use std::{env, fs::File, path::PathBuf, process::Command}; | ||
|
|
||
| // Metadata that will be collected by Movey | ||
| #[derive(serde::Serialize, Default)] | ||
| pub struct MoveyUploadRequest { | ||
| github_repo_url: String, | ||
| total_files: usize, | ||
| token: String, | ||
| subdir: String, | ||
| } | ||
|
|
||
| /// Upload the package metadata to Movey.net. | ||
| #[derive(Parser)] | ||
| #[clap(name = "movey-upload")] | ||
| pub struct MoveyUpload; | ||
|
|
||
| impl MoveyUpload { | ||
ea-open-source marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pub fn execute(self, path: Option<PathBuf>) -> anyhow::Result<()> { | ||
| if let Some(path) = path { | ||
| if path.exists() && path.is_dir() { | ||
| let _ = env::set_current_dir(&path); | ||
| } else { | ||
| bail!("invalid directory") | ||
| } | ||
| } | ||
| // make sure it's a Move project | ||
| let move_toml = File::open("Move.toml"); | ||
| if move_toml.is_err() { | ||
| bail!("Move.toml not found") | ||
| } | ||
| let metadata = move_toml.unwrap().metadata()?; | ||
| if metadata.len() == 0 { | ||
| bail!("Move.toml not found") | ||
| } | ||
|
|
||
| // use git command to get the repository url | ||
| let mut movey_upload_request: MoveyUploadRequest = Default::default(); | ||
| let mut output = Command::new("git") | ||
| .current_dir(".") | ||
| .args(&["remote", "-v"]) | ||
| .output() | ||
| .unwrap(); | ||
| if !output.status.success() || output.stdout.is_empty() { | ||
| bail!("invalid git repository") | ||
| } | ||
|
|
||
| let lines = String::from_utf8_lossy(output.stdout.as_slice()); | ||
| let lines = lines.split("\n"); | ||
| for line in lines { | ||
| if line.contains("github.com") { | ||
| let tokens: Vec<&str> = line.split(&['\t', ' '][..]).collect(); | ||
| if tokens.len() != 3 { | ||
| bail!("invalid remote url") | ||
| } | ||
| // convert ssh url to https | ||
| let https_url = if tokens[1].starts_with("git@github.com") { | ||
| tokens[1].replace(":", "/").replace("git@", "https://") | ||
| } else { | ||
| String::from(tokens[1]) | ||
| }; | ||
| movey_upload_request.github_repo_url = if https_url.ends_with(".git") { | ||
| https_url[..https_url.len() - 4].to_string() | ||
| } else { | ||
| https_url | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| // use git command to get the subdir if move package is not on the top level | ||
| output = Command::new("git") | ||
| .current_dir(".") | ||
| .args(&["rev-parse", "--show-prefix"]) | ||
| .output() | ||
| .unwrap(); | ||
| let subdir = String::from_utf8_lossy(output.stdout.as_slice()); | ||
| movey_upload_request.subdir = String::from(subdir); | ||
|
|
||
| // use git command to count total files | ||
| output = Command::new("git") | ||
| .current_dir(".") | ||
| .args(&["ls-files"]) | ||
| .output() | ||
| .unwrap(); | ||
| let tracked_files = String::from_utf8_lossy(output.stdout.as_slice()); | ||
| let tracked_files: Vec<&str> = tracked_files.split("\n").collect(); | ||
| let mut total_files = tracked_files.len(); | ||
| for file_path in tracked_files { | ||
| if file_path.is_empty() { | ||
| total_files -= 1; | ||
| continue; | ||
| } | ||
| } | ||
| movey_upload_request.total_files = total_files; | ||
| movey_upload_request.token = movey_credential::get_registry_api_token(&MOVE_HOME)?; | ||
| let movey_url = movey_credential::get_movey_url(&MOVE_HOME); | ||
| match movey_url { | ||
| Ok(url) => { | ||
| let client = Client::new(); | ||
| let response = client | ||
| .post(&format!("{}/api/v1/packages/upload", &url)) | ||
| .json(&movey_upload_request) | ||
| .send(); | ||
| match response { | ||
| Ok(response) => { | ||
| if response.status().is_success() { | ||
| println!( | ||
| "Your package has been successfully uploaded to Movey at {}/packages/{}.", | ||
| url, | ||
| response.text()? | ||
| ); | ||
| } else if response.status().is_client_error() { | ||
| bail!("{}", response.text()?) | ||
| } else if response.status().is_server_error() { | ||
| bail!("An unexpected error occurred. Please try again later"); | ||
| } | ||
| } | ||
| Err(_) => { | ||
| bail!("An unexpected error occurred. Please try again later"); | ||
| } | ||
| } | ||
| } | ||
| Err(_) => bail!("An unexpected error occurred. Please try again later"), | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // Copyright (c) The Move Contributors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| pub mod movey_credential; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.