Skip to content

Commit c15f6de

Browse files
authored
chore: Update CI with new actions and change renovate schedule (#25)
* chore: change to run renovate quarterly * add github ci actions * prettierignore renovate.json * tune schedule according to pr comment
1 parent 86afbdb commit c15f6de

File tree

6 files changed

+221
-3
lines changed

6 files changed

+221
-3
lines changed

.github/pull_request_template.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
[For internal use] 
3+
Copy the task id from the bottom of the sidebar and paste it after FTRACK-
4+
5+
Resolves FTRACK-
6+
7+
-->
8+
9+
- [ ] I have added automatic tests where applicable
10+
- [ ] The PR title is suitable as a release note
11+
- [ ] The PR contains a description of what has been changed
12+
- [ ] The description contains manual test instructions
13+
14+
## Changes
15+
16+
<!--
17+
What are you changing and what is the reason? If there are any UI changes, include a screenshot for the changes.
18+
-->
19+
20+
## Test
21+
22+
<!--
23+
How should this be tested? Include any requirements on other repositories or environment.
24+
For bug fixes, include the original reproduction steps.
25+
-->

.github/scripts/ftrack-sync.mjs

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { v5 as uuid } from "uuid";
2+
3+
if (!process.env.FTRACK_API_KEY || !process.env.PR_JSON) {
4+
console.error(`This script is intended to be run in CI only. To run locally for development, use:
5+
FTRACK_API_KEY="[dev api key]" PR_JSON='{"url":"https://github.com/ftrackhq/frontend/pull/120","body":"Resolves FTRACK-c018c026-3599-11ed-8012-aab5768efa1e"}' node ftrack-sync.mjs
6+
`);
7+
process.exit(1);
8+
}
9+
10+
const UUID_NAMESPACE = "1b671a64-40d5-491e-99b0-da01ff1f3341";
11+
12+
const requestHeaders = {
13+
"ftrack-api-key": process.env.FTRACK_API_KEY,
14+
"Content-Type": "application/json",
15+
"Response-Type": "application/json",
16+
"ftrack-user": "github_bot@ftrack.com",
17+
"ftrack-bulk": "true",
18+
};
19+
20+
function getTaskIdsAndNoteIdsFromBody(body, prUrl) {
21+
const taskIds = Array.from(body.matchAll(/FTRACK-([\w\d-]+)/g)).map(
22+
(match) => match[1]
23+
);
24+
// generate a unique id for each note based on PR.html_url and taskId
25+
const uuids = taskIds.map((taskId) => ({
26+
noteId: uuid(prUrl + taskId, UUID_NAMESPACE),
27+
taskId,
28+
}));
29+
30+
return uuids;
31+
}
32+
33+
async function groupIntoExistingAndNewNoteIds(noteIds) {
34+
const response = await (
35+
await fetch("https://dev.ftrackapp.com/api", {
36+
method: "POST",
37+
headers: requestHeaders,
38+
body: JSON.stringify([
39+
{
40+
action: "query",
41+
expression: `select id, parent_id from Note where id in (${noteIds
42+
.map(({ noteId }) => noteId)
43+
.join(",")})`,
44+
},
45+
]),
46+
})
47+
).json();
48+
49+
try {
50+
const existingIds = response[0].data.map((note) => ({
51+
noteId: note.id,
52+
taskId: note.parent_id,
53+
}));
54+
const newIds = noteIds.filter(
55+
({ noteId }) =>
56+
!existingIds
57+
.map(({ noteId: existingNoteId }) => existingNoteId)
58+
.includes(noteId)
59+
);
60+
return { existingIds, newIds };
61+
} catch (error) {
62+
console.error("Error fetching existing notes - response:", response);
63+
throw error;
64+
}
65+
}
66+
67+
function getNoteRequestBody(action, prUrl, { noteId, taskId }) {
68+
const linkDescription = prUrl.match(/\.com\/(.+)/)[1];
69+
70+
const content = `PR opened: [${linkDescription}](${prUrl})
71+
72+
Last change: ${new Date().toISOString().replace("T", " ").slice(0, -8)} GMT`;
73+
74+
return {
75+
action,
76+
entity_key: noteId,
77+
entity_type: "Note",
78+
entity_data: {
79+
id: noteId,
80+
parent_id: taskId,
81+
content,
82+
parent_type: "TypedContext",
83+
user_id: "76a40852-359d-11ed-8012-aab5768efa1e",
84+
},
85+
};
86+
}
87+
88+
export async function getNotesRequestBody(PR) {
89+
if (!PR.body) return [];
90+
const taskIds = getTaskIdsAndNoteIdsFromBody(PR.body, PR.html_url);
91+
if (taskIds.length === 0) return [];
92+
const { existingIds, newIds } = await groupIntoExistingAndNewNoteIds(taskIds);
93+
return [
94+
...newIds.map(getNoteRequestBody.bind(this, "create", PR.html_url)),
95+
...existingIds.map(getNoteRequestBody.bind(this, "update", PR.html_url)),
96+
];
97+
}
98+
99+
const PR_JSON = JSON.parse(process.env.PR_JSON);
100+
console.log("Input:", PR_JSON);
101+
const notes = await getNotesRequestBody(PR_JSON);
102+
103+
if (notes.length === 0) {
104+
console.log("Couldn't find any notes to update, exiting...");
105+
process.exit(0);
106+
}
107+
108+
console.log("Creating notes:", notes);
109+
110+
try {
111+
const response = await (
112+
await fetch("https://dev.ftrackapp.com/api", {
113+
method: "POST",
114+
headers: requestHeaders,
115+
body: JSON.stringify(notes),
116+
})
117+
).json();
118+
console.log("Response: ", response);
119+
} catch (err) {
120+
console.error(err);
121+
}

.github/workflows/check-pr-title.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Check PR title
2+
3+
permissions:
4+
pull-requests: read
5+
6+
on:
7+
pull_request:
8+
types:
9+
- opened
10+
- edited
11+
- synchronize
12+
13+
jobs:
14+
main:
15+
name: Validate PR title
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: amannn/action-semantic-pull-request@v4
19+
with:
20+
types: |
21+
feat
22+
fix
23+
docs
24+
style
25+
refactor
26+
perf
27+
test
28+
build
29+
ci
30+
chore
31+
revert
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/ftrack-sync.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: ftrack Sync
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
10+
jobs:
11+
main:
12+
name: Sync PR
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: 8BitJonny/gh-get-current-pr@2.1.1
17+
id: PR
18+
with:
19+
sha: ${{ github.event.pull_request.head.sha }}
20+
- name: Use Node.js 18.x
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: 18.x
24+
- name: node ftrack-sync.mjs
25+
run: |
26+
cd .github/scripts
27+
npm init -y && npm install uuid
28+
node ftrack-sync.mjs
29+
env:
30+
FTRACK_API_KEY: ${{ secrets.FTRACK_API_KEY }}
31+
PR_JSON: ${{ steps.PR.outputs.pr }}

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ coverage/
33
build/
44
dist/
55
.eggs/
6+
renovate.json

renovate.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{
22
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3-
"extends": ["config:base"],
4-
"enabledManagers": ["npm"],
5-
"rangeStrategy": "update-lockfile"
3+
"extends": [
4+
"config:base"
5+
],
6+
"enabledManagers": [
7+
"npm"
8+
],
9+
"rangeStrategy": "update-lockfile",
10+
"schedule": [
11+
"every month on the first day of the month"
12+
]
613
}

0 commit comments

Comments
 (0)