bitsbeats / drone-tree-config

Drone helper for mono repositories.
Apache License 2.0
103 stars 24 forks source link

Fix for `@cron` triggers #24

Closed mach6 closed 4 years ago

mach6 commented 4 years ago

Git repo paths do not start with "/"

Prior to this fix, it was possible that a @cron associated with the non-default branch would return the incorrect config data.


This PR fixes the following error;

given a repo, with a default (typically master) branch, that contains some tree;

$ tree -a .                                                                        
.
└── README.md

0 directories, 1 file

and a @cron established for the same repo, configured for branch foo, which contains a different tree;

$ tree -a .                                                                   
.
├── component_a
│   └── .drone.yml
├── component_b
│   └── .drone.yml
└── README.md

2 directories, 3 files

if the latest commit ref for foo is abcde12345, and assuming a GitHub repository, the existing code would call repos/{slug}/contents//?ref=abcde12345 which would return the tree for the default branch. This is due to the extra / before the query string in the request. See the default when ref is omitted per the documentation - https://developer.github.com/v3/repos/contents/#get-contents

The expected behavior for a @cron (and with drone-tree-config) is to walk the entire tree for the branch configured in Drone.



Note: I have not tested this change with the bitbucket and gitlab SCM's. This said, the following documentation (and code) suggests that / as a prefix is also not expected, for them;

foosinn commented 4 years ago

Good catch, thanks a lot!

I'll release a new version once your other patch is fixed.