Skip to content

Commit 6516926

Browse files
committed
Repo is now provided as OWNER/REPO instead of full url
1 parent 502805a commit 6516926

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

.github/workflows/generate-diff.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
-v $(pwd)/pull-request:/target-branch \
3535
-v $(pwd)/output:/output \
3636
-e TARGET_BRANCH=${{ github.head_ref }} \
37-
-e GIT_REPO="$(git config --get remote.origin.url)" \
37+
-e REPO=${{ github.repository }} \
3838
dagandersen/argocd-diff-preview:latest
3939
4040
- name: Post diff as comment

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ jobs:
146146
-v $(pwd)/pull-request:/target-branch \
147147
-v $(pwd)/output:/output \
148148
-e TARGET_BRANCH=${{ github.head_ref }} \
149-
-e GIT_REPO="$(git config --get remote.origin.url)" \
149+
-e REPO=${{ github.repository }} \
150150
dagandersen/argocd-diff-preview:latest
151151
152152
- name: Post diff as comment
@@ -254,9 +254,9 @@ OPTIONS:
254254
--base-branch-folder <folder> Base branch folder [env: BASE_BRANCH_FOLDER=] [default: base-branch]
255255
-i, --diff-ignore <diff-ignore> Ignore lines in diff. Example: use 'v[1,9]+.[1,9]+.[1,9]+' for ignoring changes caused by version changes following semver [env: DIFF_IGNORE=]
256256
-r, --file-regex <file-regex> Regex to filter files. Example: "/apps_.*\.yaml" [env: FILE_REGEX=]
257-
-g, --git-repo <git-repository> Git repository URL [env: GIT_REPO=]
258257
--local-cluster-tool <tool> Local cluster tool. Options: kind, minikube [env: LOCAL_CLUSTER_TOOL=] [default: auto]
259258
-o, --output-folder <output-folder> Output folder where the diff will be saved [env: OUTPUT_FOLDER=] [default: ./output]
259+
--repo <repo> Git Repository. Format: OWNER/REPO [env: REPO=]
260260
-s, --secrets-folder <secrets-folder> Secrets folder where the secrets are read from [env: SECRETS_FOLDER=] [default: ./secrets]
261261
-t, --target-branch <target-branch> Target branch name [env: TARGET_BRANCH=]
262262
--target-branch-folder <folder> Target branch folder [env: TARGET_BRANCH_FOLDER=] [default: target-branch]

makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local-test-cargo:
99
cd base-branch && gh repo clone $(github_org)/$(gitops_repo) -- --depth=1 --branch "$(base_branch)" && cp -r $(gitops_repo)/. base-branch && rm -rf .git && echo "*" > .gitignore && rm -rf $(gitops_repo) && cd -
1010
cd target-branch && gh repo clone $(github_org)/$(gitops_repo) -- --depth=1 --branch "$(target_branch)" && cp -r $(gitops_repo)/. target-branch && rm -rf .git && echo "*" > .gitignore && rm -rf $(gitops_repo) && cd -
1111

12-
cargo run -- -b "$(base_branch)" -t "$(target_branch)" -g "https://github.com/$(github_org)/$(gitops_repo).git" -r "$(regex)" --debug
12+
cargo run -- -b "$(base_branch)" -t "$(target_branch)" --repo $(github_org)/$(gitops_repo) -r "$(regex)" --debug
1313

1414
local-test-docker:
1515
# Pull repos
@@ -29,6 +29,6 @@ local-test-docker:
2929
-v $(PWD)/secrets:/secrets \
3030
-e BASE_BRANCH=$(base_branch) \
3131
-e TARGET_BRANCH=$(target_branch) \
32-
-e GIT_REPO="https://github.com/$(github_org)/$(gitops_repo).git" \
32+
-e REPO=$(github_org)/$(gitops_repo) \
3333
-e FILE_REGEX=$(regex) \
3434
image-arm64

src/main.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ struct Opt {
6060
#[structopt(long, env, default_value = "target-branch")]
6161
target_branch_folder: String,
6262

63-
/// Git repository URL
64-
#[structopt(short = "g", long = "git-repo", env = "GIT_REPO")]
65-
git_repository: String,
63+
/// Git Repository. Format: OWNER/REPO
64+
#[structopt(long = "repo", env)]
65+
repo: String,
6666

6767
/// Output folder where the diff will be saved
6868
#[structopt(short, long, default_value = "./output", env)]
@@ -132,7 +132,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
132132
let base_branch_folder = opt.base_branch_folder;
133133
let target_branch_name = opt.target_branch;
134134
let target_branch_folder = opt.target_branch_folder;
135-
let repo = opt.git_repository;
135+
let repo = opt.repo;
136136
let diff_ignore = opt.diff_ignore;
137137
let timeout = opt.timeout;
138138
let output_folder = opt.output_folder.as_str();
@@ -150,6 +150,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
150150
}
151151
};
152152

153+
let repo_regex = Regex::new(r"^[a-zA-Z0-9-]+/[a-zA-Z0-9-]+$").unwrap();
154+
if !repo_regex.is_match(&repo) {
155+
error!("❌ Invalid repository format. Please use OWNER/REPO");
156+
panic!("Invalid repository format");
157+
}
158+
153159
info!("✨ Running with:");
154160
info!("✨ - local-cluster-tool: {:?}", tool);
155161
info!("✨ - base-branch: {}", base_branch_name);
@@ -158,7 +164,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
158164
info!("✨ - target-branch-folder: {}", target_branch_folder);
159165
info!("✨ - secrets-folder: {}", secrets_folder);
160166
info!("✨ - output-folder: {}", output_folder);
161-
info!("✨ - git-repo: {}", repo);
167+
info!("✨ - repo: {}", repo);
162168
info!("✨ - timeout: {} seconds", timeout);
163169
if let Some(a) = file_regex.clone() {
164170
info!("✨ - file-regex: {}", a.as_str());

src/parsing.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,13 @@ async fn patch_argocd_applications(
100100
if spec["source"]["repoURL"]
101101
.as_str()
102102
.unwrap()
103-
.trim_end_matches(".git")
104-
== repo
103+
.contains(repo)
105104
{
106105
spec["source"]["targetRevision"] = serde_yaml::Value::String(branch.to_string());
107106
}
108107
} else if spec.contains_key("sources") {
109108
for source in spec["sources"].as_sequence_mut().unwrap() {
110-
if source["repoURL"].as_str().unwrap().trim_end_matches(".git") == repo {
109+
if source["repoURL"].as_str().unwrap().contains(repo) {
111110
source["targetRevision"] = serde_yaml::Value::String(branch.to_string());
112111
}
113112
}

0 commit comments

Comments
 (0)