-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto configure new repo (only with GH app) #890
Auto configure new repo (only with GH app) #890
Conversation
Codecov Report
@@ Coverage Diff @@
## main #890 +/- ##
==========================================
- Coverage 63.93% 63.79% -0.15%
==========================================
Files 80 81 +1
Lines 5182 5264 +82
==========================================
+ Hits 3313 3358 +45
- Misses 1560 1587 +27
- Partials 309 319 +10
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
76384c3
to
245b69c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One caveat with this implementation is that it only works with newly created repo, but I would imagine this would be more used when existing repos are there and the github apps is installed and then they use PAC...
- apiGroups: [""] | ||
resources: ["secrets"] | ||
verbs: ["get", "create"] | ||
- apiGroups: ["pipelinesascode.tekton.dev"] | ||
resources: ["repositories"] | ||
verbs: ["list"] | ||
verbs: ["create", "list"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit annoying thing to give! I wish we could separate those capaibilities depending of feature being enabled or not...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah it is possible to do through operator, if enabled then update the controller role.
not possible directly with PAC I think 🤔
but gets complicated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it complicated with operator or when doing it with PAC,
I wonder if we should just disable it by default, document it and let the operator handles it?
I don't think everyone would be using this feature....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with operator it will be easy actually depending on what user configure we an update the role
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg/adapter/adapter.go
Outdated
return | ||
} | ||
l.logger.Infof("repository configuration detected: configuring: %v, err: %v", configuring, err) | ||
l.writeResponse(response, http.StatusOK, "rejected") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not understanding this code, is the info string wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if its a repository event -> detected
is returned as true
then if the action is created
-> configuring
is returned as true
here if action is other than created then we return the response as ok but saying rejected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I think I messed it up here.. the status code too
its not a async execution..
- will return statusCreated is we configure it
- or just okay if we don't do anything
wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
status created sounds fine, did you look in the github documentation if they expect something back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. I was looking into in if we install github app on all repositories does the old repo emit any event 🤔 but nope. we have 2 ways now...
|
(about importing existing repo since this PR handles only newly created repos). maybe having a import flag in the CLI could solve this, it will :
will go over every repos in the this could be used as well for other git providers too, but we need to check with @siamaksade and koustav if that's a customer use case |
yeah but here user will need to provide token, CLI could be an option |
245b69c
to
c3c0396
Compare
|
} | ||
|
||
func generateNamespaceName(nsTemplate string, gitEvent *github.RepositoryEvent) (string, error) { | ||
repoOwner, repoName, err := formatting.GetRepoOwnerSplitted(gitEvent.Repo.GetHTMLURL()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetRepoOwnerSplitter try to handle weird edge case for gitlab or other vcs naming, perhaps you can just use splitGithubURL which should be more robust for github
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetRepoOwnerSplitter is doing a lot more things .. and it error out on normal git url like https://github.com/openshift-pipelines/pipelines-as-code
GetRepoOwnerSplitted just split and return owner and repo which is fine I think here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errors out here
return "", "", "", "", fmt.Errorf("URL %s does not seem to be a proper provider url: %w", uri, err) |
not sure why that condition is
<=
🤔 any reason to have =
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's at least org/repo/path, == would be no subpath too
c3c0396
to
a1fd135
Compare
l.writeResponse(response, http.StatusOK, "failed to configure") | ||
return | ||
} | ||
l.writeResponse(response, http.StatusOK, "skipped event") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would look weird in log can you write which event has been skipped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't log this here, this is api response
we log here
logger.Infof("github: repository event \"%v\" is not supported", repoEvent.GetAction()) |
for skipped repo events
supports template for generating namespace for repos Signed-off-by: Shivam Mukhade <[email protected]>
3596e9b
to
08fecbd
Compare
if
auto-configure-new-github-repo
is enabled in pac configmapthen PAC will auto configure newly created GitHub Repositories
it will create Repository CR and a namespace
By default if the github repository is
pac/test-repo
then it will create namespace with name
test-repo-pipelines
and repository with nametest-repo
User can provide template for generating name for namespace using
auto-configure-repo-namespace-template
Changes
Submitter Checklist
make test lint
before submitting a PR (ie: with pre-commit, no need to waste CPU cycle on CI