Skip to content

Commit b310af2

Browse files
authored
add footer file
1 parent a610599 commit b310af2

File tree

7 files changed

+68
-2
lines changed

7 files changed

+68
-2
lines changed

sprints/sprint 12/footer.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
----------
2+
3+
Codespaces

src/interfaces/IConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ import { IRepoSourceConfig } from './IRepoSourceConfig';
22

33
export interface IConfig {
44
boardIssue: string;
5+
headerFileUrl?: string;
6+
footerFileUrl?: string;
57
repos: IRepoSourceConfig[];
68
}

src/interfaces/IParsedFileUrl.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface IParsedFileUrl {
2+
owner: string;
3+
repo: string;
4+
path: string;
5+
}

src/main.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,24 @@ async function run(): Promise<void> {
9494
)
9595

9696
const issueBody = result.join('\n') + '\n';
97-
const { status } = await projectKit.updateBoardIssue(TEST_CONFIG.boardIssue, issueBody);
97+
98+
let header;
99+
if (TEST_CONFIG.headerFileUrl) {
100+
header = await projectKit.getBoardHeaderText(TEST_CONFIG.headerFileUrl);
101+
}
102+
103+
let footer;
104+
if (TEST_CONFIG.footerFileUrl) {
105+
footer = await projectKit.getBoardHeaderText(TEST_CONFIG.footerFileUrl);
106+
}
107+
108+
const issueContents = [
109+
header,
110+
issueBody,
111+
footer,
112+
].join('\n');
113+
114+
const { status } = await projectKit.updateBoardIssue(TEST_CONFIG.boardIssue, issueContents);
98115

99116
if (status !== 200) {
100117
throw new Error(`Failed to update the issue ${TEST_CONFIG.boardIssue}.`);

src/octokit/ProjectsOctoKit.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { TRepoIssue } from '../interfaces/TRepoIssue';
77
import { OctoKitBase } from './OctoKitBase';
88
import { TColumnTypes } from '../interfaces/TColumnTypes';
99
import { parseIssueUrl } from '../utils/parseIssueUrl';
10+
import { parseFileUrl } from '../utils/parseFileUrl';
1011

1112
type TColumnsMap = Record<TColumnTypes, TProjectColumn>;
1213

@@ -125,7 +126,7 @@ export class ProjectsOctoKit extends OctoKitBase {
125126
return cardIssues;
126127
}
127128

128-
public updateBoardIssue = async (issueUrl: string, body: string): Promise<any> => {
129+
public updateBoardIssue = async (issueUrl: string, body: string) => {
129130
const { owner, repo, issueNumber } = parseIssueUrl(issueUrl);
130131

131132
return await this.kit.issues.update({
@@ -135,4 +136,20 @@ export class ProjectsOctoKit extends OctoKitBase {
135136
body,
136137
});
137138
}
139+
140+
public getBoardHeaderText = async (fileUrl: string): Promise<string> => {
141+
const fileRef = parseFileUrl(fileUrl);
142+
143+
const { data } = await this.kit.repos.getContent({
144+
accept: 'application/vnd.github.VERSION.raw',
145+
...fileRef,
146+
});
147+
148+
const { content } = data;
149+
150+
const buff = Buffer.from(content, 'base64');
151+
const text = buff.toString('ascii');
152+
153+
return text;
154+
}
138155
}

src/testConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { IConfig } from './interfaces/IConfig';
22

33
export const TEST_CONFIG: IConfig = {
44
boardIssue: 'https://github.com/legomushroom/codespaces-board/issues/12',
5+
headerFileUrl: 'https://raw.githubusercontent.com/legomushroom/codespaces-board/main/sprints/sprint%2012/header.md',
6+
footerFileUrl: 'https://raw.githubusercontent.com/legomushroom/codespaces-board/main/sprints/sprint%2012/footer.md',
57
repos: [
68
{
79
owner: 'legomushroom',

src/utils/parseFileUrl.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { IParsedFileUrl } from '../interfaces/IParsedFileUrl';
2+
3+
export const parseFileUrl = (fileUrl: string): IParsedFileUrl => {
4+
const uri = new URL(fileUrl);
5+
const { pathname } = uri;
6+
7+
const split = pathname.split('/');
8+
9+
console.log(split);
10+
11+
const path = decodeURIComponent(split.slice(4).join('/'));
12+
13+
console.log(path);
14+
15+
return {
16+
owner: split[1],
17+
repo: split[2],
18+
path: `/${path}`,
19+
};
20+
};

0 commit comments

Comments
 (0)