aboutsummaryrefslogtreecommitdiffstats
path: root/src
AgeCommit message (Collapse)Author
2020-08-04Add license (GNU GPLv3+)Teddy Wing
2020-08-03Config: Add a version argumentTeddy Wing
Allow getting the program version from the command line.
2020-08-02Remove `main.rs`Teddy Wing
We have multiple binaries in `src/bin/`, so this file is no longer needed.
2020-08-02Add documentation commentsTeddy Wing
Light documentation for our various functions and types.
2020-08-02Move suggestion arguments check to `Config::get`Teddy Wing
Since this check for suggestion arguments is in both binaries, we can move it to the common preflight function. Clean up other areas now that we moved the function.
2020-08-02git-sugapply: Copy over new logic from `git-sugpatch`Teddy Wing
Use the new logic from `git-sugpatch` to build a `Config` and run `apply()` on all suggestion input arguments.
2020-08-02Config: Add description to `--github-token` argumentTeddy Wing
2020-08-02Config: Add description to `--remote` argumentTeddy Wing
2020-08-02Add `-h` argumentTeddy Wing
Print usage on `-h` and `--help`. Store the usage brief on `Config` in order to be able to print it from multiple places.
2020-08-02git-sugpatch: Print usage with no suggestion argumenetTeddy Wing
Add `Options` to `Config` to allow us to get a usage string from a `Config` instance, which is where we create `Options`. Needed to remove the `Debug` derive on `Config` in order to add the field as `Options` doesn't implement `Debug`.
2020-08-02Config: Remove old lineTeddy Wing
This was a test, before I worked out the API for this function.
2020-08-02git-sugpatch: Exit with `EX_USAGE` if no suggestion argumentsTeddy Wing
Replace my test exit code with a real one.
2020-08-02git-sugpatch: Replace `unwrap` with printed error message and exitTeddy Wing
2020-08-02for_suggestion: Replace `unwrap`s with exitsTeddy Wing
Print the error and exit.
2020-08-02lib.rs: Make `owner_repo` module privateTeddy Wing
Turns out this didn't need to be public at all.
2020-08-02git-sugpatch: Move the suggestion arguments loop to a new functionTeddy Wing
Split this out into a separate function because I want to reuse it in `git-sugapply`.
2020-08-02git-sugpatch: Fix `SuggestionUrl` parsingTeddy Wing
Forgot to change this line when I set up the loop over suggestion arguments. We want to parse the current argument instead of hard-coding the first one.
2020-08-02lib.rs: Make `owner_repo` `pub(crate)` againTeddy Wing
Made this `pub` for one of the test tries in 38a871f28bad90e238021d8cc46b9fa926f9df75, but in the end it wasn't necessary. Restore this to the prior visibility.
2020-08-02config::Error::EnvVar: Include the variable name in the error messageTeddy Wing
The source error's message doesn't include the name. Ensure we print the name of the variable we're trying to get so that users know which one is missing.
2020-08-02config::Error::Opts: Include source error in messageTeddy Wing
Ensure the source error is surfaced.
2020-08-02git-sugpatch: Clean up after 38a871f28bad90e238021d8cc46b9fa926f9df75Teddy Wing
Remove unused code.
2020-08-02git-sugpatch: Error if no remote and suggestion ID argumentTeddy Wing
We want to allow not having a remote when URL arguments are given, but require it when a suggestion ID argument is given (otherwise we wouldn't have an owner-repo pair to make the GitHub request). Had some trouble with the `OwnerRepo.o_r` value. It was being moved into the closure, so tried a loop. There was a similar problem with the loop. However, by returning, I was able to get a reference to the `Result` instead of having it be moved.
2020-08-02git-sugpatch: Print error and exit on `Config::get` errorTeddy Wing
Add `exitcode` to exit with an appropriate code. Add the `gseprintln` macro to wrap `eprintln!()`, prefixing the output with "error: ".
2020-08-02git-sugpatch: Accept multiple suggestion args; Accept suggestion ID argsTeddy Wing
Add the ability to pass multiple suggestions to the binary. The diffs will appear in the output one after another. Also allow suggestions to be specified by their comment ID instead of their full URL. This uses the Git repo's remote to determine the owner-repo pair. When a URL argument is given, the owner-repo pair is extracted from the URL. It's now possible to call the binary like this: $ git-sugpatch 459692838 \ > https://github.com/teddywing/suggestion-test/pull/1#discussion_r459691747
2020-08-01Config: Add suggestion argumentsTeddy Wing
Store the suggestion references specified on the command line.
2020-08-01OwnerRepo: Parse from SSH-style pathsTeddy Wing
Remotes can be HTTP URLs or use SSH/SCP-style paths like: git@github.com/teddywing/github-suggestion.git We need to handle both regular URLs and the above style, which isn't parseable by the 'url' crate. Add a custom parsing function to get the owner and repo from this format. When trying to parse `OwnerRepo` from a string, first try to parse it as a URL. If that fails with a `RelativeUrlWithoutBase` error, assume it's the other style of reference.
2020-08-01Config: Extract `remote` into functionTeddy Wing
2020-08-01Config: Move `github_token` to a functionTeddy Wing
Improve organisation.
2020-08-01Get configTeddy Wing
We need the following values in order to build a `Client`: * GitHub token * Repo owner * Repo name Get the token from a command-line argument, or else the Git config, or else an environment variable. Get the repo identifiers from the repo's remote URL. Use the remote specified as a command-line argument, otherwise get it from the Git config, or else default to "origin". TODO: Only try to get the owner-name pair from the remote if a comment ID was given, not if a URL argument was passed.
2020-08-01OwnerRepo: Move `identifier_for_remote` to `OwnerRepo::from_remote`Teddy Wing
Since this function returns an `OwnerRepo`, make it a method on the struct.
2020-08-01lib.rs: Move code to `owner_repo.rs`Teddy Wing
Need to add other code to the library.
2020-08-01Move `github-suggestion-cli` to the root crateTeddy Wing
This will be used by the binaries.
2020-08-01Move library to a separate crateTeddy Wing
Keep the binaries in the root crate, and add a new crate for the `github-suggestion` library. I want to add some library code to the CLI programs to extract common functionality between the different binaries.
2020-08-01SuggestionUrl: Return an error if path has less than two segmentsTeddy Wing
We need two segments in the path to parse the owner-repo combination.
2020-07-29Rename crate to 'github-suggestion'Teddy Wing
Didn't like the old name. Wanted to make the GitHub reference more explicit. I remember it as "suggestion", since that's the name of the GitHub feature, so "suggested" was confusing. The final "patch" seemed redundant or unnecessary.
2020-07-29suggestion.rs: Remove research testsTeddy Wing
These weren't actual tests. I was using them to research different implementation approaches.
2020-07-29Suggestion: Return `Result` from `apply()` and `apply_to()`Teddy Wing
Replace `unwrap`s with trys.
2020-07-29Suggestion.suggestion_with_line_ending: Return `Result`Teddy Wing
Remove the `unwrap` in this method and return a `Result`.
2020-07-29Suggestion: Remove unused `suggestion()` and `suggestion_patch()`Teddy Wing
These methods are no longer used.
2020-07-29Suggestion: Remove `unwrap`s and return `Result`s from diff methodsTeddy Wing
Extend the `Error` enum with new variants to capture the possible errors from `diff()` and `diff_with_repo()`.
2020-07-28Suggestion: Remove unused `patch` methodTeddy Wing
The newer `Suggestion.diff()` method fulfills the same need.
2020-07-28Client::new(): Return a `Result`Teddy Wing
Wrap `Github` client errors.
2020-07-28client.rs: Remove superfluous testTeddy Wing
I had written this to check the response from the server and the 'github-rs' library. Remove it since it makes a network request.
2020-07-28Move `Client` to a new moduleTeddy Wing
2020-07-28Move `Suggestion` to a new moduleTeddy Wing
Planning to separate the `Suggestion` and `Client` code.
2020-07-28Suggestion.apply(): Error when patch doesn't applyTeddy Wing
Don't apply the patch when it doesn't apply, instead fail with an error. Previously, the `apply()` method would apply the patch to the lines from `Suggestion`, even if the file was different from what the suggestion expected. So, you could end up with the `Suggestion` lines being overwritten with the suggestion text, even when they didn't match the original side of the suggestion. Fix this by getting the diff text from `diff_with_repo()` and applying it using `git-apply`. This gives us a suitable error when the patch doesn't apply to the file, leaving the file alone.
2020-07-27Test `Suggestion.diff()`Teddy Wing
Add a test for diff generation. Split `diff()` into `diff_with_repo()` to allow us to test with a new repo instead of defaulting to the current one. In the test, create a new Git repo using `git2`, add and commit a file, and check that the diff generated by a Suggestion is correct. Got the `IndexEntry` format from https://docs.rs/git2/0.13.8/src/git2/index.rs.html#858-871.
2020-07-26Suggestion.apply_to(): Change `from` to be `BufRead`Teddy Wing
Take a `BufRead`er instead of a file path to read from. This gives us more flexibility. We can't use the `Read` trait because of the error described in b4a7561ccc1ed7dab6cd2c786902dec8c4ad9be6. Fix the bug in `Suggestion.diff()` so that the suggestion is applied to the commit it corresponds to instead of HEAD.
2020-07-26Suggestion: Update tests to add new `commit` fieldTeddy Wing
2020-07-26Suggestion: Add `diff` methodTeddy Wing
Create a patch file for the suggestion. Instead of building the patch text manually, as in my earlier attempts (`patch` and `unified_diff`), apply the patch to the file in memory, and then ask libgit2 to give us a Git patch by comparing the original blob and the patched buffer. Doing this because I was unsuccessful in manually composing a patch file that Git would accept. I could create unified diffs that the `patch` program would accept, but these wouldn't work with `git-apply`. My current guess is that these didn't work because I didn't have both before and after context in my manually-created patch files. Since this tool is intended to be used with Git, I want a patch file that will work transparently with Git utilities. The easiest alternative to manually generating the patch file seemed to be to have Git create the patch text. Add a new binary, `git-sugpatch`, that outputs the patch text to standard output. TODO: This gets the original from the current HEAD in `apply_to()`. We should instead be using the contents of `blob`, because the original is not necessarily the working copy.