Add function to get commit diff/patch #589

Merged
6543 merged 4 commits from Gusted/go-sdk:add-commit-diff-patch into master 2022-05-14 22:16:26 +00:00
Contributor
- Adds function the gets a commit's diff or patch. - Ref: https://github.com/go-gitea/gitea/pull/17095
Gusted added 1 commit 2022-05-02 01:42:25 +00:00
Add function to get commit diff/patch
- Adds function the gets a commit's diff or patch.
- Ref: https://github.com/go-gitea/gitea/pull/17095
Some checks failed
continuous-integration/drone/pr Build is failing
dcc87ca2f9
Gusted added 1 commit 2022-05-02 01:48:24 +00:00
Simplify code
All checks were successful
continuous-integration/drone/pr Build is passing
89391bc5d7
Owner

I wonder if two funcs would make sense.
One for diff, one for patch?

I wonder if two funcs would make sense. One for diff, one for patch?
Author
Contributor

Functions aren't that big, so should be alright.

Functions aren't that big, so should be alright.
Gusted added 1 commit 2022-05-02 01:56:49 +00:00
Split function
All checks were successful
continuous-integration/drone/pr Build is passing
3c184a4f2e
jolheiser approved these changes 2022-05-02 01:57:58 +00:00
dachary approved these changes 2022-05-07 16:16:48 +00:00
Owner

I think it should be one func

similar to:

https://gitea.com/gitea/go-sdk/src/branch/master/gitea/pull.go#L275-L283

you can also reuse the const's and make the type public ...

I think it should be one func similar to: https://gitea.com/gitea/go-sdk/src/branch/master/gitea/pull.go#L275-L283 you can also reuse the const's and make the type public ...
Author
Contributor

I think it should be one func

similar to:

https://gitea.com/gitea/go-sdk/src/branch/master/gitea/pull.go#L275-L283

you can also reuse the const's and make the type public ...

We'd just moved away from using a generic function. I think making the function names more explicit is a good API design.

> I think it should be one func > > similar to: > > https://gitea.com/gitea/go-sdk/src/branch/master/gitea/pull.go#L275-L283 > > you can also reuse the const's and make the type public ... We'd just moved away from using a generic function. I think making the function names more explicit is a good API design.
Owner

I think the difference is that the "generic" func is non-exported in the PR case.

I'm not against that approach, mostly I think the exported funcs being explicitly named is the design choice.

Whether those exported funcs call a generic non-exported func or not is 50/50 for me since there's only a handful of lines.


I remain approving of this PR, but would also approve a non-exported generic func that the other two invoke.

I think the difference is that the "generic" func is non-exported in the PR case. I'm not against that approach, mostly I think the _exported_ funcs being explicitly named is the design choice. Whether those exported funcs call a generic non-exported func or not is 50/50 for me since there's only a handful of lines. ----- I remain approving of this PR, but would also approve a non-exported generic func that the other two invoke.
6543 reviewed 2022-05-14 15:28:13 +00:00
@ -116,0 +124,4 @@
return nil, nil, err
}
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/git/commits/%s.diff", user, repo, commitID), nil, nil)
Owner
-	return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/git/commits/%s.diff", user, repo, commitID), nil, nil)
+	return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/git/commits/%s.%s", user, repo, commitID, pullRequestDiffTypeDiff), nil, nil)
```diff - return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/git/commits/%s.diff", user, repo, commitID), nil, nil) + return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/git/commits/%s.%s", user, repo, commitID, pullRequestDiffTypeDiff), nil, nil) ```
6543 marked this conversation as resolved
@ -116,0 +137,4 @@
return nil, nil, err
}
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/git/commits/%s.patch", user, repo, commitID), nil, nil)
Owner
-	return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/git/commits/%s.patch", user, repo, commitID), nil, nil)
+	return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/git/commits/%s.%s", user, repo, commitID, pullRequestDiffTypePatch), nil, nil)
```diff - return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/git/commits/%s.patch", user, repo, commitID), nil, nil) + return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/git/commits/%s.%s", user, repo, commitID, pullRequestDiffTypePatch), nil, nil) ```
6543 marked this conversation as resolved
Owner

☝️ with this if there will be some refactor any time, code lookup will work

☝️ with this if there will be some refactor any time, code lookup will work
Author
Contributor

☝️ with this if there will be some refactor any time, code lookup will work

Could you eloborate on this? Why should we use a argument for a constant string?

> ☝️ with this if there will be some refactor any time, code lookup will work Could you eloborate on this? Why should we use a argument for a constant string?
Gusted added 1 commit 2022-05-14 22:14:00 +00:00
Use constant strings
Some checks failed
continuous-integration/drone/pr Build is failing
90703be8cd
6543 approved these changes 2022-05-14 22:14:50 +00:00
6543 merged commit f3ebdb8afe into master 2022-05-14 22:16:26 +00:00
Gusted deleted branch add-commit-diff-patch 2022-05-15 11:20:39 +00:00
Sign in to join this conversation.
No description provided.