Skip to content

Commit

Permalink
Show yml config of pipeline in UI (woodpecker-ci#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
anbraten authored Jan 9, 2022
1 parent 5e59597 commit 37c82b9
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 2 deletions.
24 changes: 24 additions & 0 deletions server/api/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,30 @@ func GetProcLogs(c *gin.Context) {
}
}

func GetBuildConfig(c *gin.Context) {
_store := store.FromContext(c)
repo := session.Repo(c)
num, err := strconv.ParseInt(c.Param("number"), 10, 64)
if err != nil {
_ = c.AbortWithError(http.StatusBadRequest, err)
return
}

build, err := _store.GetBuildNumber(repo, num)
if err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
}

configs, err := _store.ConfigsForBuild(build.ID)
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}

c.JSON(http.StatusOK, configs)
}

// DeleteBuild cancels a build
func DeleteBuild(c *gin.Context) {
_store := store.FromContext(c)
Expand Down
1 change: 1 addition & 0 deletions server/router/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func apiRoutes(e *gin.Engine) {

repo.GET("/builds", api.GetBuilds)
repo.GET("/builds/:number", api.GetBuild)
repo.GET("/builds/:number/config", api.GetBuildConfig)

// requires push permissions
repo.POST("/builds/:number", session.MustPush, api.PostBuild)
Expand Down
17 changes: 16 additions & 1 deletion web/src/lib/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import ApiClient, { encodeQueryString } from './client';
import { Build, BuildFeed, BuildLog, BuildProc, Registry, Repo, RepoPermissions, RepoSettings, Secret } from './types';
import {
Build,
BuildConfig,
BuildFeed,
BuildLog,
BuildProc,
Registry,
Repo,
RepoPermissions,
RepoSettings,
Secret,
} from './types';

type RepoListOptions = {
all?: boolean;
Expand Down Expand Up @@ -49,6 +60,10 @@ export default class WoodpeckerClient extends ApiClient {
return this._get(`/api/repos/${owner}/${repo}/builds/${number}`) as Promise<Build>;
}

getBuildConfig(owner: string, repo: string, number: number): Promise<BuildConfig[]> {
return this._get(`/api/repos/${owner}/${repo}/builds/${number}/config`) as Promise<BuildConfig[]>;
}

getBuildFeed(opts?: Record<string, string | number | boolean>): Promise<BuildFeed[]> {
const query = encodeQueryString(opts);
return this._get(`/api/user/feed?${query}`) as Promise<BuildFeed[]>;
Expand Down
6 changes: 6 additions & 0 deletions web/src/lib/api/types/buildConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// A config for a build.
export type BuildConfig = {
hash: string;
name: string;
data: string;
};
1 change: 1 addition & 0 deletions web/src/lib/api/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './build';
export * from './buildConfig';
export * from './registry';
export * from './repo';
export * from './secret';
Expand Down
6 changes: 6 additions & 0 deletions web/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ const routes: RouteRecordRaw[] = [
component: (): Component => import('~/views/repo/build/Build.vue'),
props: true,
},
{
path: 'config',
name: 'repo-build-config',
component: (): Component => import('~/views/repo/build/BuildConfig.vue'),
props: true,
},
],
},
{
Expand Down
58 changes: 58 additions & 0 deletions web/src/views/repo/build/BuildConfig.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<template>
<FluidContainer v-if="buildConfigs" class="flex flex-col gap-y-6 text-gray-500 justify-between !py-0">
<Panel v-for="buildConfig in buildConfigs" :key="buildConfig.hash" :title="buildConfig.name">
<span class="font-mono whitespace-pre">{{ buildConfig.data }}</span>
</Panel>
</FluidContainer>
</template>

<script lang="ts">
import { defineComponent, inject, onMounted, Ref, ref, watch } from 'vue';
import FluidContainer from '~/components/layout/FluidContainer.vue';
import Panel from '~/components/layout/Panel.vue';
import useApiClient from '~/compositions/useApiClient';
import { Build, BuildConfig, Repo } from '~/lib/api/types';
export default defineComponent({
name: 'BuildConfig',
components: {
FluidContainer,
Panel,
},
setup() {
const build = inject<Ref<Build>>('build');
const apiClient = useApiClient();
const repo = inject<Ref<Repo>>('repo');
if (!repo || !build) {
throw new Error('Unexpected: "repo" & "build" should be provided at this place');
}
const buildConfigs = ref<BuildConfig[]>();
async function loadBuildConfig() {
if (!repo || !build) {
throw new Error('Unexpected: "repo" & "build" should be provided at this place');
}
buildConfigs.value = (await apiClient.getBuildConfig(repo.value.owner, repo.value.name, build.value.number)).map(
(i) => ({
...i,
data: atob(i.data),
}),
);
}
onMounted(() => {
loadBuildConfig();
});
watch(build, () => {
loadBuildConfig();
});
return { buildConfigs };
},
});
</script>
12 changes: 11 additions & 1 deletion web/src/views/repo/build/BuildWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<div class="flex flex-wrap gap-y-2 items-center justify-between">
<Tabs v-model="activeTab" disable-hash-mode>
<Tab id="tasks" title="Tasks" />
<Tab id="config" title="Config" />
</Tabs>

<div class="flex justify-between gap-x-4 text-gray-500 flex-shrink-0 ml-auto">
Expand Down Expand Up @@ -63,7 +64,7 @@ import {
toRef,
watch,
} from 'vue';
import { useRouter } from 'vue-router';
import { useRoute, useRouter } from 'vue-router';
import Button from '~/components/atomic/Button.vue';
import IconButton from '~/components/atomic/IconButton.vue';
Expand Down Expand Up @@ -122,6 +123,7 @@ export default defineComponent({
setup(props) {
const apiClient = useApiClient();
const route = useRoute();
const router = useRouter();
const notifications = useNotifications();
const favicon = useFavicon();
Expand Down Expand Up @@ -191,12 +193,20 @@ export default defineComponent({
const activeTab = computed({
get() {
if (route.name === 'repo-build-config') {
return 'config';
}
return 'tasks';
},
set(tab: string) {
if (tab === 'tasks') {
router.replace({ name: 'repo-build' });
}
if (tab === 'config') {
router.replace({ name: 'repo-build-config' });
}
},
});
Expand Down

0 comments on commit 37c82b9

Please sign in to comment.