-
Notifications
You must be signed in to change notification settings - Fork 45
Bot support for github revisions #3254
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
595b3e7
Support Github revision with backend generic provider
vrigal 9de73ea
Update tests
vrigal 58f7006
Github support fixes
vrigal af8dd7d
Use a + to slugify github repositories
vrigal dd278a0
Update test
vrigal 2a7eea0
Use the information from the decision task
vrigal 9e920b3
Replace - delimiter by +
vrigal 09b050c
Replace + in the repository slug by a _
vrigal dd7a1cc
Update tests
vrigal b8087cc
Fix backend unit test
e2efd96
Share cache by default
078ef44
Use same arguments as for phab rev
1c19e05
Store changesets too
b7d273c
Clone git repo
78a3a77
Fix local git path
b9c02f5
Remove unused fixture
vrigal 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
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,76 @@ | ||
| from urllib.parse import urlparse | ||
|
|
||
| import structlog | ||
| from git import Repo | ||
|
|
||
| logger = structlog.getLogger(__name__) | ||
|
|
||
|
|
||
| def build_repo_slug(repo_url): | ||
| """ | ||
| Build a slug from a github repository url | ||
| mozilla-firefox/firefox would become mozilla-firefox_firefox | ||
| This method copies the automatic slug creation in backend's RepositoryGetOrCreateField serializer field. | ||
| """ | ||
| parts = urlparse(repo_url) | ||
| assert parts.netloc == "github.com", "Only github repositories are supported" | ||
|
|
||
| path = parts.path.lstrip("/") | ||
| if path.endswith(".git"): | ||
| path = path[:-4] | ||
|
|
||
| return path.replace("/", "_") | ||
|
|
||
|
|
||
| def git_clone(base_repository, head_repository, revision, destination): | ||
| """ | ||
| Clone a git repo at a specific revision in a directory | ||
| If the repo is already present, fetches and checkout | ||
| """ | ||
|
|
||
| # Build slug | ||
| base_slug = build_repo_slug(base_repository) | ||
| head_slug = build_repo_slug(head_repository) | ||
|
|
||
| logger.info(base_slug, head_slug) | ||
|
|
||
| # Clone or fetch upstream | ||
| path = destination / base_slug | ||
| if path.exists() and (path / ".git").is_dir(): | ||
| logger.info("Use existing repo", path=path) | ||
| repo = Repo.init(path) | ||
|
|
||
| # Make sure origin matches the url | ||
| origin = repo.remotes["origin"] | ||
| if origin.url != base_repository: | ||
| logger.info("Update remote origin", url=base_repository) | ||
| origin.set_url(base_repository) | ||
|
|
||
| # Always update the references for base repo | ||
| logger.info("Fetch remote origin") | ||
| origin.fetch() | ||
| else: | ||
| logger.info("Clone git repository", url=base_repository, path=path) | ||
| repo = Repo.clone_from(base_repository, path) | ||
|
|
||
| # Fetch head repository as a remote on top of base | ||
| try: | ||
| head = repo.remotes[head_slug] | ||
|
|
||
| # Make sure head matches the url | ||
| if head.url != head_repository: | ||
| head.set_url(head_repository) | ||
|
|
||
| except IndexError: | ||
| # Setup new remote | ||
| head = repo.create_remote(head_slug, head_repository) | ||
|
|
||
| # Always fetch, as creating a remote does not fetch automatically | ||
| logger.info("Fetch remote head", url=head.url) | ||
| head.fetch() | ||
|
|
||
| # Detach head to specified revision | ||
| logger.info("Checkout to head", revision=revision) | ||
| repo.head.reference = repo.commit(revision) | ||
|
|
||
| return repo |
Empty file.
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
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.