Skip to content

Commit

Permalink
Merge branch 'master' into when_on_root
Browse files Browse the repository at this point in the history
  • Loading branch information
anbraten authored Sep 3, 2022
2 parents 95e37d3 + 7db7e97 commit 2695014
Show file tree
Hide file tree
Showing 14 changed files with 271 additions and 31 deletions.
4 changes: 2 additions & 2 deletions server/pipeline/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (

// Cancel the build and returns the status.
func Cancel(ctx context.Context, store store.Store, repo *model.Repo, build *model.Build) error {
if build.Status != model.StatusRunning && build.Status != model.StatusPending {
return ErrBadRequest{Msg: "Cannot cancel a non-running or non-pending build"}
if build.Status != model.StatusRunning && build.Status != model.StatusPending && build.Status != model.StatusBlocked {
return ErrBadRequest{Msg: "Cannot cancel a non-running or non-pending or non-blocked build"}
}

procs, err := store.ProcList(build)
Expand Down
149 changes: 149 additions & 0 deletions server/remote/gitea/fixtures/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,155 @@ const HookPush = `
}
`

// HookPushBranch is a sample Gitea push hook where a new branch was created from an existing commit
const HookPushBranch = `
{
"ref": "refs/heads/fdsafdsa",
"before": "0000000000000000000000000000000000000000",
"after": "28c3613ae62640216bea5e7dc71aa65356e4298b",
"compare_url": "https://codeberg.org/meisam/woodpecktester/compare/master...28c3613ae62640216bea5e7dc71aa65356e4298b",
"commits": [],
"head_commit": {
"id": "28c3613ae62640216bea5e7dc71aa65356e4298b",
"message": "Delete '.woodpecker/.check.yml'\n",
"url": "https://codeberg.org/meisam/woodpecktester/commit/28c3613ae62640216bea5e7dc71aa65356e4298b",
"author": {
"name": "meisam",
"email": "meisam@noreply.codeberg.org",
"username": "meisam"
},
"committer": {
"name": "meisam",
"email": "meisam@noreply.codeberg.org",
"username": "meisam"
},
"verification": null,
"timestamp": "2022-07-12T21:09:27+02:00",
"added": [],
"removed": [
".woodpecker/.check.yml"
],
"modified": []
},
"repository": {
"id": 50820,
"owner": {
"id": 14844,
"login": "meisam",
"full_name": "",
"email": "meisam@noreply.codeberg.org",
"avatar_url": "https://codeberg.org/avatars/96512da76a14cf44e0bb32d1640e878e",
"language": "",
"is_admin": false,
"last_login": "0001-01-01T00:00:00Z",
"created": "2020-10-08T11:19:12+02:00",
"restricted": false,
"active": false,
"prohibit_login": false,
"location": "",
"website": "",
"description": "Materials engineer, physics enthusiast, large collection of the bad programming habits, always happy to fix the old ones and make new mistakes!",
"visibility": "public",
"followers_count": 0,
"following_count": 0,
"starred_repos_count": 0,
"username": "meisam"
},
"name": "woodpecktester",
"full_name": "meisam/woodpecktester",
"description": "Just for testing the Woodpecker CI and reporting bugs",
"empty": false,
"private": false,
"fork": false,
"template": false,
"parent": null,
"mirror": false,
"size": 367,
"language": "",
"languages_url": "https://codeberg.org/api/v1/repos/meisam/woodpecktester/languages",
"html_url": "https://codeberg.org/meisam/woodpecktester",
"ssh_url": "git@codeberg.org:meisam/woodpecktester.git",
"clone_url": "https://codeberg.org/meisam/woodpecktester.git",
"original_url": "",
"website": "",
"stars_count": 0,
"forks_count": 0,
"watchers_count": 1,
"open_issues_count": 0,
"open_pr_counter": 0,
"release_counter": 0,
"default_branch": "master",
"archived": false,
"created_at": "2022-07-04T00:34:39+02:00",
"updated_at": "2022-07-24T20:31:29+02:00",
"permissions": {
"admin": true,
"push": true,
"pull": true
},
"has_issues": true,
"internal_tracker": {
"enable_time_tracker": true,
"allow_only_contributors_to_track_time": true,
"enable_issue_dependencies": true
},
"has_wiki": true,
"has_pull_requests": true,
"has_projects": true,
"ignore_whitespace_conflicts": false,
"allow_merge_commits": true,
"allow_rebase": true,
"allow_rebase_explicit": true,
"allow_squash_merge": true,
"default_merge_style": "merge",
"avatar_url": "",
"internal": false,
"mirror_interval": "",
"mirror_updated": "0001-01-01T00:00:00Z",
"repo_transfer": null
},
"pusher": {
"id": 2628,
"login": "6543",
"full_name": "",
"email": "6543@obermui.de",
"avatar_url": "https://codeberg.org/avatars/09a234c768cb9bca78f6b2f82d6af173",
"language": "",
"is_admin": false,
"last_login": "0001-01-01T00:00:00Z",
"created": "2019-10-12T05:05:49+02:00",
"restricted": false,
"active": false,
"prohibit_login": false,
"location": "",
"visibility": "public",
"followers_count": 22,
"following_count": 16,
"starred_repos_count": 55,
"username": "6543"
},
"sender": {
"id": 2628,
"login": "6543",
"full_name": "",
"email": "6543@obermui.de",
"avatar_url": "https://codeberg.org/avatars/09a234c768cb9bca78f6b2f82d6af173",
"language": "",
"is_admin": false,
"last_login": "0001-01-01T00:00:00Z",
"created": "2019-10-12T05:05:49+02:00",
"restricted": false,
"active": false,
"prohibit_login": false,
"visibility": "public",
"followers_count": 22,
"following_count": 16,
"starred_repos_count": 55,
"username": "6543"
}
}
`

// HookPushTag is a sample Gitea tag hook
const HookPushTag = `{
"sha": "ef98532add3b2feb7a137426bba1248724367df5",
Expand Down
34 changes: 22 additions & 12 deletions server/remote/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"path"
"path/filepath"
"strings"
"time"

"code.gitea.io/sdk/gitea"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -84,22 +85,27 @@ func (c *Gitea) Name() string {
return "gitea"
}

func (c *Gitea) oauth2Config() *oauth2.Config {
func (c *Gitea) oauth2Config(ctx context.Context) (*oauth2.Config, context.Context) {
return &oauth2.Config{
ClientID: c.ClientID,
ClientSecret: c.ClientSecret,
Endpoint: oauth2.Endpoint{
AuthURL: fmt.Sprintf(authorizeTokenURL, c.URL),
TokenURL: fmt.Sprintf(accessTokenURL, c.URL),
ClientID: c.ClientID,
ClientSecret: c.ClientSecret,
Endpoint: oauth2.Endpoint{
AuthURL: fmt.Sprintf(authorizeTokenURL, c.URL),
TokenURL: fmt.Sprintf(accessTokenURL, c.URL),
},
RedirectURL: fmt.Sprintf("%s/authorize", server.Config.Server.OAuthHost),
},
RedirectURL: fmt.Sprintf("%s/authorize", server.Config.Server.OAuthHost),
}

context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: c.SkipVerify},
Proxy: http.ProxyFromEnvironment,
}})
}

// Login authenticates an account with Gitea using basic authentication. The
// Gitea account details are returned when the user is successfully authenticated.
func (c *Gitea) Login(ctx context.Context, w http.ResponseWriter, req *http.Request) (*model.User, error) {
config := c.oauth2Config()
config, oauth2Ctx := c.oauth2Config(ctx)

// get the OAuth errors
if err := req.FormValue("error"); err != "" {
Expand All @@ -117,7 +123,7 @@ func (c *Gitea) Login(ctx context.Context, w http.ResponseWriter, req *http.Requ
return nil, nil
}

token, err := config.Exchange(ctx, code)
token, err := config.Exchange(oauth2Ctx, code)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -158,10 +164,14 @@ func (c *Gitea) Auth(ctx context.Context, token, secret string) (string, error)
// Refresh refreshes the Gitea oauth2 access token. If the token is
// refreshed the user is updated and a true value is returned.
func (c *Gitea) Refresh(ctx context.Context, user *model.User) (bool, error) {
config := c.oauth2Config()
config, oauth2Ctx := c.oauth2Config(ctx)
config.RedirectURL = ""

source := config.TokenSource(ctx, &oauth2.Token{RefreshToken: user.Secret})
source := config.TokenSource(oauth2Ctx, &oauth2.Token{
AccessToken: user.Token,
RefreshToken: user.Secret,
Expiry: time.Unix(user.Expiry, 0),
})

token, err := source.Token()
if err != nil || len(token.AccessToken) == 0 {
Expand Down
6 changes: 6 additions & 0 deletions server/remote/gitea/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func buildFromPush(hook *pushHook) *model.Build {
link := hook.Compare
if len(hook.Commits) > 0 {
message = hook.Commits[0].Message
} else {
message = hook.HeadCommit.Message
}

if len(hook.Commits) == 1 {
Expand Down Expand Up @@ -115,6 +117,10 @@ func getChangedFilesFromPushHook(hook *pushHook) []string {
files = append(files, c.Modified...)
}

files = append(files, hook.HeadCommit.Added...)
files = append(files, hook.HeadCommit.Removed...)
files = append(files, hook.HeadCommit.Modified...)

return utils.DedupStrings(files)
}

Expand Down
15 changes: 15 additions & 0 deletions server/remote/gitea/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,20 @@ func Test_parser(t *testing.T) {
g.Assert(utils.EqualStringSlice(b.ChangedFiles, []string{"CHANGELOG.md", "app/controller/application.rb"})).IsTrue()
})
})
g.Describe("given a push hook from an branch creation", func() {
g.It("should extract repository and build details", func() {
buf := bytes.NewBufferString(fixtures.HookPushBranch)
req, _ := http.NewRequest("POST", "/hook", buf)
req.Header = http.Header{}
req.Header.Set(hookEvent, hookPush)
r, b, err := parseHook(req)
g.Assert(err).IsNil()
g.Assert(r).IsNotNil()
g.Assert(b).IsNotNil()
g.Assert(b.Event).Equal(model.EventPush)
g.Assert(b.Message).Equal("Delete '.woodpecker/.check.yml'\n")
g.Assert(b.ChangedFiles).Equal([]string{".woodpecker/.check.yml"})
})
})
})
}
20 changes: 12 additions & 8 deletions server/remote/gitea/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@

package gitea

type commit struct {
ID string `json:"id"`
Message string `json:"message"`
URL string `json:"url"`
Added []string `json:"added"`
Removed []string `json:"removed"`
Modified []string `json:"modified"`
}

type pushHook struct {
Sha string `json:"sha"`
Ref string `json:"ref"`
Expand Down Expand Up @@ -42,14 +51,9 @@ type pushHook struct {
} `json:"owner"`
} `json:"repository"`

Commits []struct {
ID string `json:"id"`
Message string `json:"message"`
URL string `json:"url"`
Added []string `json:"added"`
Removed []string `json:"removed"`
Modified []string `json:"modified"`
} `json:"commits"`
Commits []commit `json:"commits"`

HeadCommit commit `json:"head_commit"`

Sender struct {
ID int64 `json:"id"`
Expand Down
4 changes: 3 additions & 1 deletion web/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ declare module '@vue/runtime-core' {
IEntypoDotsTwoVertical: typeof import('~icons/entypo/dots-two-vertical')['default']
IGgTrash: typeof import('~icons/gg/trash')['default']
IIcBaselineDarkMode: typeof import('~icons/ic/baseline-dark-mode')['default']
IIcBaselineDownload: typeof import('~icons/ic/baseline-download')['default']
IIcBaselineDownloadForOffline: typeof import('~icons/ic/baseline-download-for-offline')['default']
IIcBaselineEdit: typeof import('~icons/ic/baseline-edit')['default']
IIcBaselineFileDownload: typeof import('~icons/ic/baseline-file-download')['default']
IIcBaselineFileDownloadOff: typeof import('~icons/ic/baseline-file-download-off')['default']
IIcBaselineHealing: typeof import('~icons/ic/baseline-healing')['default']
IIconoirArrowLeft: typeof import('~icons/iconoir/arrow-left')['default']
IIconParkOutlineAlarmClock: typeof import('~icons/icon-park-outline/alarm-clock')['default']
Expand Down
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@intlify/vite-plugin-vue-i18n": "^6.0.0",
"@kyvg/vue3-notification": "^2.3.6",
"@meforma/vue-toaster": "^1.3.0",
"@vueuse/core": "^9.1.1",
"ansi_up": "^5.1.0",
"dayjs": "^1.11.4",
"floating-vue": "^2.0.0-beta.19",
Expand Down
4 changes: 3 additions & 1 deletion web/src/assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@
"canceled": "This step has been canceled.",
"cancel_success": "Pipeline canceled",
"restart_success": "Pipeline restarted",
"log_download": "Download"
"log_download": "Download",
"log_auto_scroll": "Automatically scroll down",
"log_auto_scroll_off": "Turn off automatic scrolling"
},
"protected": {
"awaits": "This pipeline is awaiting approval by some maintainer!",
Expand Down
4 changes: 3 additions & 1 deletion web/src/assets/locales/lv.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@
"canceled": "Šis solis tika atcelts.",
"cancel_success": "Konvejerdarbs atcelts",
"restart_success": "Konvejerdarbs pārstartēts",
"log_download": "Lejupielādēt"
"log_download": "Lejupielādēt",
"log_auto_scroll": "Automātiski ritināt",
"log_auto_scroll_off": "Atslēgt automātisko ritināšanu"
},
"protected": {
"awaits": "Šim konvejerdarbam ir nepieciešams apstiprinājums no atbildīgajām personām!",
Expand Down
8 changes: 6 additions & 2 deletions web/src/components/atomic/Icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
<i-mdi-chevron-right v-else-if="name === 'chevron-right'" class="h-6 w-6" />
<i-carbon-close-outline v-else-if="name === 'close'" class="h-6 w-6" />
<i-ic-baseline-edit v-else-if="name === 'edit'" class="h-6 w-6" />
<i-ic-baseline-download v-else-if="name === 'download'" class="h-6 w-6" />
<i-ic-baseline-download-for-offline v-else-if="name === 'download'" class="h-6 w-6" />
<i-icon-park-outline-alarm-clock v-else-if="name === 'stopwatch'" class="h-6 w-6" />
<i-ic-baseline-file-download v-else-if="name === 'auto-scroll'" class="h-6 w-6" />
<i-ic-baseline-file-download-off v-else-if="name === 'auto-scroll-off'" class="h-6 w-6" />
<div v-else-if="name === 'blank'" class="h-6 w-6" />
</template>

Expand Down Expand Up @@ -84,7 +86,9 @@ export type IconNames =
| 'close'
| 'edit'
| 'stopwatch'
| 'download';
| 'download'
| 'auto-scroll'
| 'auto-scroll-off';
export default defineComponent({
name: 'Icon',
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/build-feed/BuildFeedSidebar.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div
v-if="isBuildFeedOpen"
class="flex flex-col overflow-y-auto items-center bg-white dark:bg-dark-gray-800 dark:border-dark-500"
class="flex flex-col z-50 overflow-y-auto items-center bg-white dark:bg-dark-gray-800 dark:border-dark-500"
>
<router-link
v-for="build in sortedBuildFeed"
Expand Down
Loading

0 comments on commit 2695014

Please sign in to comment.