-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add automation to create a gitlab project #73
Merged
Merged
Conversation
This file contains 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
We can't use the `_post` helper because it sends the response before it returns :(
This is pretty meaty so I created it as a free-standing commit with associated tests. The context will be used in future commits.
This is the primary interface for this module.
This is a useful helper that creates a CompensatingAction that runs a single SQL query.
I only verify the first order dependencies currently.
Using a protocol instead of type alias here since it lets us match the default parameters.
I'm going to be adding a new parameter so this makes things a lot more readable ;)
It turns out that we need this to interact with the GitLabClient.
I bumped the version of flake8 due to some pyflakes defects around `# type: ignore[misc]`. Unfortunately this will have to be followed up by another commit to adjust for changes in the flake8 plugins :(
This required a handle on the active user. Since there is only one user of this client, I just add a new param.
We should pass along the status code from GitLab in the vast majority of cases. For example, anything that makes Imbi produce a "Bad Request" on the GitLab API shouldn't be retried... it is usually caused by incorrect configuration somewhere in the Imbi data but that is nothing that an automatic retry is going to fix. The only exception is that we should never reflect a Not Authorized response from GitLab since it would be interpreted as the Imbi user not being authorized against Imbi.
This is in the imbi.automations namespace since that is where our allow listed functionality lives. The creation code itself is straight forward. I do need to figure out how to isolate the SQL code to create identifiers and links... I'm going to live with the technical debt for the time being since we need a more functional model layer to really address the problem.
pre-commit needs to have the git command available and it only works in a git repository so .... install git, and git add in /tmp/test.
in-op
reviewed
Apr 29, 2024
in-op
reviewed
Apr 29, 2024
This didn't work on some long past version of GitLab even though it is the recommended approach in the RFC. Works now though!
This was referenced May 2, 2024
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR builds on top of #72 by adding the
imbi.automations.gitlab.create_project
function that can be used as an automation callable. It does required that you have an OAuth 2 application defined in GitLab that is used to authorize Imbi to act as a specific GitLab user. You will need the OAuth 2 Client ID and Client Secret for that application to continue (details below).Once you have the GitLab connection configured and a user connected, creating a new project of a project type that has automations enabled will add toggles for each available automation to the display.
![image](https://private-user-images.githubusercontent.com/350812/323766368-c77ec078-bab7-4138-a7f4-2cda6843d67f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk5NDI0ODQsIm5iZiI6MTczOTk0MjE4NCwicGF0aCI6Ii8zNTA4MTIvMzIzNzY2MzY4LWM3N2VjMDc4LWJhYjctNDEzOC1hN2Y0LTJjZGE2ODQzZDY3Zi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxOVQwNTE2MjRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02NzJjNmY4NTgxM2VjMmNmNjQyOWE2NzhkYTZlMGRlMzM1ODA5NGIwNGIwMDU5YjFiYmNmNGY3YzFmMTUwN2I3JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.iC52tiZdnQkmbN4cuxjHMTHQqk7TGCXzl_8hdSpv6RM)
After creating the Imbi project, the project creation endpoint will run the selected automations (8400ff4). If none of the automations fail, then the endpoint responds with a 👍 to the client. If any automation fails, then any successful automations are rolled back, the Imbi project is deleted, and a 👎 is returned to the client. The only automation implemented in this PR is one to create a GitLab project (e775720). The project location is determined by the
namespace.gitlab_group_name
andproject_type.gitlab_project_prefix
. If either is missing, then the slug is substituted. There are a few interesting error conditions that can pop up:Feel free to play around with different settings. The error handling can be changed fairly easily... as long as we can determine what to do programatically.
You will also need AWeber-Imbi/imbi-ui#73 running to see the new UI options.
Guru meditations
automations:gitlab:
in the configuration file?Enabling the OAuth 2 connection and automation
GitLab OAuth 2 Application Details
Confidential ☑️
Scopes
api
Redirect URI (one per line)
Script to enable GitLab OAuth 2 integration & automation