Skip to content

Commit 427fe0d

Browse files
committed
fix: return 201 Created status for variable creation API
- Change API response status for variable creation from 204 No Content to 201 Created - Update integration tests to expect 201 Created status after creating variables Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent d5dc9aa commit 427fe0d

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

routers/api/v1/user/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func CreateVariable(ctx *context.APIContext) {
162162
return
163163
}
164164

165-
ctx.Status(http.StatusNoContent)
165+
ctx.Status(http.StatusCreated)
166166
}
167167

168168
// UpdateVariable update a user-level variable which is created by current doer

tests/integration/api_repo_variables_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func TestAPIRepoVariables(t *testing.T) {
138138
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
139139
Value: "initial_val",
140140
}).AddTokenAuth(token)
141-
MakeRequest(t, req, http.StatusNoContent)
141+
MakeRequest(t, req, http.StatusCreated)
142142

143143
req = NewRequest(t, "DELETE", url).AddTokenAuth(token)
144144
MakeRequest(t, req, http.StatusNoContent)

tests/integration/api_user_variables_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ func TestAPIUserVariables(t *testing.T) {
2929
},
3030
{
3131
Name: "_",
32-
ExpectedStatus: http.StatusNoContent,
32+
ExpectedStatus: http.StatusCreated,
3333
},
3434
{
3535
Name: "TEST_VAR",
36-
ExpectedStatus: http.StatusNoContent,
36+
ExpectedStatus: http.StatusCreated,
3737
},
3838
{
3939
Name: "test_var",
@@ -75,7 +75,7 @@ func TestAPIUserVariables(t *testing.T) {
7575
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
7676
Value: "initial_val",
7777
}).AddTokenAuth(token)
78-
MakeRequest(t, req, http.StatusNoContent)
78+
MakeRequest(t, req, http.StatusCreated)
7979

8080
cases := []struct {
8181
Name string
@@ -132,7 +132,7 @@ func TestAPIUserVariables(t *testing.T) {
132132
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
133133
Value: "initial_val",
134134
}).AddTokenAuth(token)
135-
MakeRequest(t, req, http.StatusNoContent)
135+
MakeRequest(t, req, http.StatusCreated)
136136

137137
req = NewRequest(t, "DELETE", url).AddTokenAuth(token)
138138
MakeRequest(t, req, http.StatusNoContent)

0 commit comments

Comments
 (0)