mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-10-05 19:30:59 +00:00
fix: event.pull_request.action == closed can use the cache of the base repository (#1031)
It was tested locally with https://code.forgejo.org/forgejo/end-to-end/pulls/1062/files. ## Before  ## After  --- When the "closed" action of a pull request event was triggered by a merge, it effectively runs in the context of the base repository. It was merged by a user with write access to the base repository. It is authorized to write the base repository cache. Resolves forgejo/runner#1030 <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/1031): <!--number 1031 --><!--line 0 --><!--description Zml4OiBldmVudC5wdWxsX3JlcXVlc3QuYWN0aW9uID09IGNsb3NlZCBjYW4gdXNlIHRoZSBjYWNoZSBvZiB0aGUgYmFzZSByZXBvc2l0b3J5-->fix: event.pull_request.action == closed can use the cache of the base repository<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1031 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
9c09ca3f56
commit
014b4ba5f6
2 changed files with 124 additions and 16 deletions
|
@ -141,6 +141,83 @@ func (m *forgejoClientMock) UpdateLog(ctx context.Context, request *connect.Requ
|
|||
}), nil
|
||||
}
|
||||
|
||||
func TestRunner_getWriteIsolationKey(t *testing.T) {
|
||||
t.Run("push", func(t *testing.T) {
|
||||
key, err := getWriteIsolationKey(t.Context(), "push", "whatever", nil)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, key)
|
||||
})
|
||||
|
||||
t.Run("pull_request synchronized key is ref", func(t *testing.T) {
|
||||
expectedKey := "refs/pull/1/head"
|
||||
actualKey, err := getWriteIsolationKey(t.Context(), "pull_request", expectedKey, map[string]any{
|
||||
"action": "synchronized",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expectedKey, actualKey)
|
||||
})
|
||||
|
||||
t.Run("pull_request synchronized ref is invalid", func(t *testing.T) {
|
||||
invalidKey := "refs/is/invalid"
|
||||
key, err := getWriteIsolationKey(t.Context(), "pull_request", invalidKey, map[string]any{
|
||||
"action": "synchronized",
|
||||
})
|
||||
require.Empty(t, key)
|
||||
assert.ErrorContains(t, err, invalidKey)
|
||||
})
|
||||
|
||||
t.Run("pull_request closed and not merged key is ref", func(t *testing.T) {
|
||||
expectedKey := "refs/pull/1/head"
|
||||
actualKey, err := getWriteIsolationKey(t.Context(), "pull_request", expectedKey, map[string]any{
|
||||
"action": "closed",
|
||||
"pull_request": map[string]any{
|
||||
"merged": false,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expectedKey, actualKey)
|
||||
})
|
||||
|
||||
t.Run("pull_request closed and merged key is empty", func(t *testing.T) {
|
||||
key, err := getWriteIsolationKey(t.Context(), "pull_request", "whatever", map[string]any{
|
||||
"action": "closed",
|
||||
"pull_request": map[string]any{
|
||||
"merged": true,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, key)
|
||||
})
|
||||
|
||||
t.Run("pull_request missing event.pull_request", func(t *testing.T) {
|
||||
key, err := getWriteIsolationKey(t.Context(), "pull_request", "whatever", map[string]any{
|
||||
"action": "closed",
|
||||
})
|
||||
require.Empty(t, key)
|
||||
assert.ErrorContains(t, err, "event.pull_request is not a map")
|
||||
})
|
||||
|
||||
t.Run("pull_request missing event.pull_request.merge", func(t *testing.T) {
|
||||
key, err := getWriteIsolationKey(t.Context(), "pull_request", "whatever", map[string]any{
|
||||
"action": "closed",
|
||||
"pull_request": map[string]any{},
|
||||
})
|
||||
require.Empty(t, key)
|
||||
assert.ErrorContains(t, err, "event.pull_request.merged is not a bool")
|
||||
})
|
||||
|
||||
t.Run("pull_request with event.pull_request.merge of an unexpected type", func(t *testing.T) {
|
||||
key, err := getWriteIsolationKey(t.Context(), "pull_request", "whatever", map[string]any{
|
||||
"action": "closed",
|
||||
"pull_request": map[string]any{
|
||||
"merged": "string instead of bool",
|
||||
},
|
||||
})
|
||||
require.Empty(t, key)
|
||||
assert.ErrorContains(t, err, "not a bool but string")
|
||||
})
|
||||
}
|
||||
|
||||
func TestRunnerCacheConfiguration(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue