I'm working with Cake and Teamcity and I'm trying to access which branch a GitHub PR is targeting
Been trying to find a GitHub API wrapper for Cake do to the job, or a plugin/script to TeamCity to populate some parameter with the value, but no luck so far.
Is there any good wrapper for Github PR in Cake or TeamCity that i have missed?
I'm certain there is nothing that you have missed.
The question would be - before searching for how to do this in Cake - how to obtain the information in the first place.
If you were building on GitHub Actions, there is the github.base_ref which GitHub populates for PRs and which would contain exactly what you are looking for.
Now, I don't know how TeamCity does the checkout so I can probably not really help you. What I can do is give you a pointer:
What AppVeyor does when building a PR is this:
git clone -q <url of repo>
cd <name-of-repo>
git fetch -q origin +refs/pull/<gh-id-of-pr>/merge:
git checkout -qf FETCH_HEAD
If you - in that state - do
git branch --contains HEAD^1
the output (at least in my tests) is:
* (HEAD detached at FETCH_HEAD)
develop
As said above, I am not sure what TC does for a PR build but I guess you'd need something along the above lines.
I, personally, would try to get the required information using git commands before checking what the GitHub API can do.
In the end I found and used the Octokit SDK for dotnet
https://github.com/octokit/octokit.net
As I for #Nils answer would also need the authorization for the repo to run the GIT commands, i went with a higher level solution more native to Cake
Related
Developers keep making the mistake on hotfixes to release branches in github. Here are the steps we have right now
git checkout --track origin/release_xxxx (make sure you are on the release branch)
git checkout -b yourName/yourTicketNumber (the hotfix branch)
Modify your code
Post a PR
modify the PR's base branch back to release_xxx
I am wondering if there is a slick way on the last step that once in a while gets missed to automatically use the branch it was branched from instead of main?
Perhaps I just need to create a postHotfix.sh and do the work in there but then people need github tools installed. Any other solutions?
I don't know of an automatic solution, but you can change the base branch when raising your PR in the GitHub UI:
If you're using the GitHub CLI, you can add a -B (or --base) branch as an argument: https://cli.github.com/manual/gh_pr_create
We are using AWS Code Commit for source code and considering moving to Github in the near future. What is the easiest way to accomplish this ? I have seen a lot of articles about importing a Github project into AWS Code commit but not the other way around.
Simplest way is to clone your code commit repo and push it to your GitHub repo.
I think this is a very fair question and none of the comments have addressed it. Though it is trivial to migrate the git repo, that is not a full clone of all meta data related to it. This is roughly:
git clone --mirror <source repo>
Create new, empty repo in a GitHub org you can write to
git add remote target <dest repo>
git push --mirror target
What gets missed doing git migrations like this is things such as users/groups permissions, pull requests, secrets, and probably other things I've forgotten. This meta data is not stored in the git repo and needs to be re-implemented on the GitHub side. As there are usually APIs to the Git systems, migration scripts can be written and some are written by GitHub, some by individuals (though I struggled to find any active examples).
I too have searched extensively for a migration tool that actually gets all the data for an AWS CodeCommit repo and reproduces it as a GitHub repo.
It looks like I should be able to write a script that uses the AWS REST API to get the data and then write it to the GitHub API. I was hoping this code already existed and I would save a bunch of time writing and debugging it.
Does anyone know if it is possible to update source files during a build (from an external source for e.g. like checking if there are new translations and merging those in) and then merge those changes to a git branch via a Pull request with TeamCity as part of the build steps?
TeamCity has an 'Automatic Merge' feature. Please have a look at the documentation and the related blog post
We are using a private GitHub Organization as version control. When a task is assigned to a developer, they fork the primary repository, make their code changes, and submit a pull request to have the changes merged into the master branch of the primary repository.
We are also using TeamCity for CI. It is currently configured to kick off a build for a VCS commit, which builds, tests, and deploys the artifact to an artifact repository internally. To accomplish this, the Team City build configuration has multiple VCS roots installed; one for the primary and 1 for each developer's fork.
The problem is that Team City pulls from all of them when a commit is made assuming they are all necessary for the build instead of allowing you to only pull from the single repository that triggered the build. Any thoughts on how we can accomplish this without having to create n build configurations in Team City for each project (where n == number of developers working on a project)?
I see way to do this with preserving current workflow is turning off automatic checkout (VCS Checkout Mode), and checking out code manually in an additional command-line build step, with a parameter %teamcity.build.branch% (logical branch name).
I.e.:
git clone ...
git checkout %teamcity.build.branch%
Triggers will just start the job if there are changes in developer's VCS root, fulfill branch env variable; no automatic checkout will happen and then build step will check out only needed branch. Only works with one git URL.
After posting in the JetBrains forums, I was pointed to a blog that answers my question.
TL;DR: my approach of using feature branches does not work with GitHub's workflow. Instead, Forks and Pull Requests should be used. The blog referenced shows how you can use Team City to trigger off of a Pull Request. Simply add +:refs/pull/*/head to "Branch Specification" in your VCS Root and all pull requests to the Source repository will trigger your Build Configuration.
Imagine situation like this on github:
repo 1
repo 2 (has dependency to repo 1 build artifact)
where both of these have travis configured.
However I'd like to run travis build of the repo 2 also in the case of successful travis build on the repo 1.
Any chance/idea how to achieve that?
The only idea I had was to:
create new user
and in case of successful travis build of repo 1 do git commit + push repo 2.
However that would lead to dirty commit history on repo 2. Well I could also remove all the new user's old commits, but that increases the complexity might be error prone.
Sorry, It's not possible to do that right now, as you can only start a travis-ci build on a commit at the moment.
Obviously not ideal, but you can, however, in repo 2, clone git repo 1, run the repo 1 unit tests in repo 2, and if they fail stop the repo 2 unit tests from running and end the build.
Unfortunately Travis CI doesn't provide this feature. There is feature request for it, but wasn't approved yet, so it's not even on roadmap so far.
This is reason why I switched to similar service: drone.io.
It's relatively new so some languages are in beta so far. Don't know if it is option for you.
It provides more features than Travis CI,
One of them is HTTPS hook for remote triggering the builds.
So you can configure repo1 Drone job to hit build hook of repo2.
This can be done via wget command (You need to wrap repo2 hook URL into double quotes).