aboutsummaryrefslogtreecommitdiffstats
path: root/src/jenkins.rs
AgeCommit message (Collapse)Author
2017-11-17find_and_track_build_and_update_status(): Send Jenkins console URLTeddy Wing
When adding a GitHub commit status, instead of using the job "home" URL, use the URL of its "Console" page. This page shows the build log and is much more useful than the other one. If there's a build failure in particular, you'd be going to this page anyway to see what the problem was, so using this `target_url` saves a click.
2017-11-17jenkins.rs: Add `jenkins_console_url_path()`Teddy Wing
A new function that will return the URL to the Jenkins "Console" page given the URL of a Jenkins job. We'll be using this to pass with the GitHub status request as the `target_url`.
2017-11-17Remove commented log calls from Jenkins requestsTeddy Wing
We're not using these any more, so they can be removed.
2017-11-17Merge remote-tracking branch 'origin/fix-final-status-update-call'Teddy Wing
Conflicts: src/jenkins.rs
2017-11-16find_and_track_build_and_update_status(): Make `info` logs `debug`Teddy Wing
These were useful during development and in bug hunting, but I get the sense that they'd be more annoying in production. Change these to `debug` log messages.
2017-11-16find_and_track_build_and_update_status(): Remove commented thread::spawnTeddy Wing
This `thread::spawn()` call was moved outside the function and into `main()`. We can remove it now.
2017-11-16find_and_track_build_and_update_status(): Restore old arg typesTeddy Wing
I had changed these when I was having trouble passing the values through my double-closure, but now that that's settles, we can revert these types to the way they were before and get rid of the unnecessary `to_owned()` transformations.
2017-11-16find_and_track_build_and_update_status(): Fix final GitHub callTeddy Wing
I had mistakenly (stupidly) used the wrong `job` variable. Duh, that's why it was sending a "pending" status when the job was finished! Use the correct variable, `updated_job`, to update the correct GitHub status.
2017-11-14find_and_track_build_and_update_status(): Move thread outside functionTeddy Wing
Instead of wrapping the inside of the function in a thread, put the thread on the outside, in `main()`. This is an effort to try to get around the `move`/lifetime issues I was having with the previous version. Add some extra logging so we have a better idea what's going on when. Remove the `expects` I had added and put the `Result` returns back. In `main()`, wrap the call to `find_and_track_build_and_update_status()` in a thread and sleep before calling it. This allows us to give Jenkins some time to warm up and create a job for our commit before we go ahead and try to request it from its API. Otherwise, if we kick off the Jenkins fetch too soon, our statuses aren't going to get updated because the job won't have been created and thus won't have been found on the `get_jobs()` call. Had to add some ugly `clone()`s to get around `move` compiler errors here. Next step is figuring out how to clean that up.
2017-11-14find_and_track_build_and_update_status(): Try to wrap the fn in a threadTeddy Wing
Try to put the whole function inside a thread. This doesn't work because of move problems. The reason for wrapping things in a thread is so I can add a `sleep` at the top of the function. We want to sleep before even making our first request to Jenkins because it seems like we're making the request too early, before the job has been created. This prevents the GitHub status from being set.
2017-11-13Focus HTTP response logging on `update_commit_status()`Teddy Wing
Comment out HTTP response logging from Jenkins because those may be coming back all right. Actually I might want to leave the log from `request_job()` now that I think about it. Add some additional logging on `update_commit_status()` to hopefully try to see why it's not getting called all the time.
2017-11-13Log response body of HTTP callsTeddy Wing
Log the HTTP response bodies to see if there's something we can gather from our connected services' API responses.
2017-11-12Add license (GNU GPLv3+)Teddy Wing
Add COPYING file and license notices to sources.
2017-11-12Convert a bunch of `to_string()`s to `to_owned()`Teddy Wing
I had used `to_owned()` previously in other projects, but after looking up the difference (again probably), I decided that it seems better to use `to_owned()`. References: https://users.rust-lang.org/t/to-string-vs-to-owned-for-string-literals/1441/6 http://www.lowlevelmanager.com/2016/02/rust-tostring-vs-toowned-for-string.html
2017-11-12request_job(): Use `Job::new()`Teddy Wing
Realised that the reason why I was getting a dead code warning from `Job::new` was not just because I wasn't using it, but because I was meant to use it somewhere. Remove the duplicate work going on in `request_job()` and replace it with a call to `Job::new()` instead.
2017-11-12Update tests for Jenkins mock URLTeddy Wing
Now that the Jenkins API URL is getting passed in via command line and function argument, update the tests to pass it in directly. Remove the test/non-test versions of `jenkins_url` from `find_and_track_build_and_update_status()` because we can pass in the mock URL directly to the `get_jobs()` and `request_job()` functions in tests. Make the `jenkins_url` argument to `find_and_track_build_and_update_status()` not a reference so that we don't have to reset it in the function to a `to_owned()` version.
2017-11-12update_commit_status(): Pass GitHub token from command line argumentTeddy Wing
Take the GitHub API token as a parameter and pass it through from `find_and_track_build_and_update_status()`.
2017-11-12Take Jenkins URL from command line optionsTeddy Wing
Get rid of the static, global `API_URL`, and replace it with the Jenkins URL that gets passed into `find_and_track_build_and_update_status()`. This necessitated adding a new URL argument to `get_jobs()` and `request_job()`. Starting to wonder if I should be creating a struct to hold the URL and client that I can attach these functions to as methods, but for now I'll leave them alone.
2017-11-12Update tests to pass a `jenkins_request_client()`Teddy Wing
Now that `get_jobs()` and `request_job()` take a `jenkins_request_client()`, update the tests to ensure we're calling them properly.
2017-11-12auth_credentials(): Get credentials from argumentsTeddy Wing
Remove the hard-coded user ID and token values. Instead, take these from arguments to the function. In order to not have to pass those arguments through to both `get_jobs()` and `request_job()`, make a new private function that builds a 'reqwest' client with the required auth header.
2017-11-12find_and_track_build_and_update_status(): Pass in configurationTeddy Wing
Pass logins & tokens for API communication into this function. Since this is the entry point into everything else, it seemed to make sense to have it be the thing that took the config. Ended up not making a Config struct to be simple. I guess.
2017-11-11Handle `Result` return values in testsTeddy Wing
Update our failing test suite to work with our new return types now that many of our functions return `Result`s. Since these are tests, we handle them by panicking with error messages.
2017-11-11find_and_track_build_and_update_status(): Elaborate `expect` messagesTeddy Wing
Make these panic messages more meaningful by adding some contextual information.
2017-11-11find_and_track_build_and_update_status(): Use `Result`sTeddy Wing
Catch `Result` errors in the spawned thread by panicking with `expect`. Couldn't figure out how to use `expect` with a custom value, in the case of `request_job`.
2017-11-11jenkins.rs: Replace `.unwrap()`s with `Result`sTeddy Wing
Return errors as `Result`s instead of panicking. Inside the thread, we can't return a result, so we need to panic errors. These should be picked up as `Result`s from a `thread.join()`.
2017-11-10find_and_track_build_and_update_status(): Fix `while` loopTeddy Wing
I got an unused variable warning on line 142 when I "reset" job at the end of the loop. But actually, I wasn't resetting it, I was creating a new variable in the inner scope. In order to update the `job` used by the `while` loop, I think we need to make `job` a mutable variable and then set it at the end of the loop.
2017-11-10Get rid of unused variablesTeddy Wing
2017-11-09find_and_track_build_and_update_status: Remove `repo_name` argumentTeddy Wing
I just looked at `CommitRef`'s definition and realised that it includes the repo name already. Whoops, turns out we didn't need this. Probably didn't occur to me because I decided not to write a test for `find_and_track_build_and_update_status` since it seemed like too much of a pain.
2017-11-09`find_and_track_build_and_update_status`: Simplify polling loopTeddy Wing
By using a while loop on the status being 'pending', we can get rid of a level of nesting.
2017-11-09`find_and_track_build_and_update_status`: Fill in thread status pollingTeddy Wing
Inside the thread, while the job is pending, poll the job on Jenkins until either its status changes (to success or failed), or until 20 minutes have passed.
2017-11-09Correct tests after 69b930565a118f1f9890492e9f3130e23091b398Teddy Wing
Now that a bunch of function signatures have been rewritten to take references, update the tests to pass the correct arguments.
2017-11-09Fix move compilation errors in `find_and_track_build_and_update_status`Teddy Wing
I had a bunch of compilation errors in this function because I wasn't borrowing correctly. Fix the errors with borrows by reference, and copying strings. Here are the errors for reference: error[E0373]: closure may outlive the current function, but it borrows `job`, which is owned by the current function --> src/jenkins.rs:89:27 | 89 | thread::spawn(|| { | ^^ may outlive borrowed value `job` ... 94 | job.result.commit_status(), | --- `job` is borrowed here | help: to force the closure to take ownership of `job` (and any other referenced variables), use the `move` keyword | 89 | thread::spawn(move || { | ^^^^^^^ error[E0373]: closure may outlive the current function, but it borrows `job_url`, which is owned by the current function --> src/jenkins.rs:89:27 | 89 | thread::spawn(|| { | ^^ may outlive borrowed value `job_url` ... 96 | job_url.clone(), | ------- `job_url` is borrowed here | help: to force the closure to take ownership of `job_url` (and any other referenced variables), use the `move` keyword | 89 | thread::spawn(move || { | ^^^^^^^ error[E0382]: use of moved value: `commit_ref` --> src/jenkins.rs:88:32 | 88 | if job_for_commit(job, commit_ref) { | ^^^^^^^^^^ value moved here in previous iteration of loop | = note: move occurs because `commit_ref` has type `pull_request::CommitRef`, which does not implement the `Copy` trait error[E0382]: capture of moved value: `commit_ref` --> src/jenkins.rs:93:21 | 88 | if job_for_commit(job, commit_ref) { | ---------- value moved here ... 93 | commit_ref, | ^^^^^^^^^^ value captured here after move | = note: move occurs because `commit_ref` has type `pull_request::CommitRef`, which does not implement the `Copy` trait error[E0382]: capture of moved value: `job` --> src/jenkins.rs:89:27 | 88 | if job_for_commit(job, commit_ref) { | --- value moved here 89 | thread::spawn(|| { | ^^ value captured here after move | = note: move occurs because `job` has type `jenkins::Job`, which does not implement the `Copy` trait error[E0382]: capture of moved value: `job_url` --> src/jenkins.rs:89:27 | 85 | let job = request_job(job_url); | ------- value moved here ... 89 | thread::spawn(|| { | ^^ value captured here after move | = note: move occurs because `job_url` has type `std::string::String`, which does not implement the `Copy` trait
2017-11-09jenkins.rs: Add `commit_status` method on `JobStatus`Teddy Wing
A new method that establishes correspondences between Jenkins statuses and GitHub statuses, so we can pass a GitHub `CommitStatus` to `update_commit_status` given a `Job`.
2017-11-09`update_commit_status`: Remove `organization_name` argumentTeddy Wing
Now that the organisation name (rather, owner of a GitHub project) is stored in `CommitRef`, we don't need to pass it in explicitly.
2017-11-09CommitRef: Add `owner` fieldTeddy Wing
This field stores the "owner" of the commit on GitHub, in other words, a user or organisation. Storing that information in this struct makes it easier to pass around.
2017-11-09github.rs: `update_commit_status` needs organisation nameTeddy Wing
I wasn't thinking straight in 26b74edece4546378c8a853cc70f7388f20ff0c6. Instead of taking a repo name, we need to take an organisation/user name. The repo name we already have from `commit_ref.repo`. We were missing the org to be able to properly construct the GitHub API URL. Pass `organization_name` name around from `find_and_track_build_and_update_status`.
2017-11-09jenkins.rs: Take repo name in `find_and_track...`Teddy Wing
This function should take a repo name so we can pass that information to `get_jobs`, as well as `update_commit_status`. Also add types to the parameters which I apparently didn't think to do the first time.
2017-11-09jenkins.rs: Start `thread` idea in main functionTeddy Wing
Use `thread::spawn` and update the GitHub commit status. Write an outline for how to handle polling for changes and updating the GitHub commit status on success or failure (or timeout).
2017-11-09jenkins.rs: Rename `update_commit_status` functionTeddy Wing
Realised tonight that I had used the same name for this function and for the function in `github.rs` that updates the commit status on GitHub. Since it doesn't really make sense for these two different functions to have the same name, rename this one to be more specific about what it does.
2017-11-08jenkins.rs: Fix `request_job` testTeddy Wing
Pass the correct URL into the function call. Previously my copy-pastes meant that the mock URL I had defined was different from the one I passed to `request_job`.
2017-11-08jenkins.rs: Allow `request_job` to work with the test mockTeddy Wing
Use the 'url' crate to split the passed in URL string and get its path part so we can use the mock HTTP server for testing. Otherwise, this requested the real Jenkins API URL and we couldn't test it.
2017-11-08jenkins.rs: Initial `request_job` implementationTeddy Wing
Try to request a job from the Jenkins API and return it as a `Job`. Trouble is, we can't mock this because the 'mockito' mocker depends on `API_URL`. Right now, we're making a request to the real server, not the mock server.
2017-11-08jenkins.rs: Add test for `request_job`Teddy Wing
This function will get a `Job` based on the response from requesting a single build job from the Jenkins API.
2017-11-08jenkins.rs: Make `get_jobs` realTeddy Wing
Instead of just making a request to test out 'reqwest' and how to use it, make this function actually do something useful. It now requests a URL dynamically based on the `repo_name` passed in, and returns a list of build job URLs from the JSON resulting from the API response.
2017-11-08jenkins.rs: Make `get_jobs` test realTeddy Wing
Instead of just calling the `get_jobs` function, make this a real test and check its return value using a mocked response, now that we have 'mockito' at our disposition.
2017-11-08jenkins.rs: Add `job_for_commit`Teddy Wing
Fill in this function, which returns a boolean whether a given job matches a `CommitRef`. It does this based on the display name of the job. Needed to make the `Job` struct public in order to use it here.
2017-11-08jenkins.rs: Add `Job::new` function to create Job from JSON payloadTeddy Wing
Now we can parse the JSON payload in a single place and extract the values from it into a new `Job`. Change `Job.result`'s type to `JobStatus` because that makes more sense. Now, `result_from_job` gets called in `Job::new` to give us the `JobStatus` directly on the `Job`. Modify `result_from_job` to fit into its new responsibility, working for `Job::new`. Update the tests accordingly.
2017-11-08jenkins.rs: Add a `Job` typeTeddy Wing
This will avoid having to parse a job JSON payload multiple times. We should do the parsing once, extract the data we need, and pass the resulting struct around instead.
2017-11-08jenkins.rs: Add `update_commit_status` outlineTeddy Wing
Outline for the main function that will integrate everything here. It carries out the algorithm described at the top of the file. So far it's incomplete, but wanted to get the idea down in code somewhere. Also, this method might make more sense in a different module.
2017-11-08jenkins.rs: Add `result_from_job`Teddy Wing
This method will take a job JSON payload returned from the Jenkins API (http://jenkins/job/:project/:id/api/json), and return its status, success, failed, or pending. A new `JobStatus` type represents the status of jobs.