Skip to content

Commit b3a1b63

Browse files
committed
Remove graphql
1 parent 0eee37d commit b3a1b63

File tree

5 files changed

+12
-192
lines changed

5 files changed

+12
-192
lines changed

packages/code-infra/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"@mui/internal-babel-plugin-resolve-imports": "workspace:*",
6060
"@next/eslint-plugin-next": "^15.5.3",
6161
"@octokit/auth-action": "^6.0.1",
62-
"@octokit/graphql": "^9.0.1",
6362
"@octokit/rest": "^22.0.0",
6463
"@pnpm/find-workspace-dir": "^1000.1.3",
6564
"babel-plugin-optimize-clsx": "^2.6.2",

packages/code-infra/src/utils/changelog.mjs

Lines changed: 3 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { graphql, GraphqlResponseError } from '@octokit/graphql';
21
import { Octokit } from '@octokit/rest';
32
import { $ } from 'execa';
43

@@ -14,10 +13,6 @@ import { $ } from 'execa';
1413
* @property {{login: string; association: AuthorAssociation} | null} author
1514
*/
1615

17-
/**
18-
* @typedef {import('./github-gql.mjs').CommitConnection} CommitConnection
19-
*/
20-
2116
/**
2217
* @param {Object} opts
2318
* @param {string} opts.cwd
@@ -51,137 +46,7 @@ export async function fetchCommitsBetweenRefs({ org = 'mui', ...options }) {
5146
}
5247
const opts = { ...options, org };
5348

54-
/**
55-
* @type {FetchedCommitDetails[]}
56-
*/
57-
try {
58-
return fetchCommitsGraphql(opts);
59-
} catch (error) {
60-
let status = 0;
61-
if (error instanceof GraphqlResponseError) {
62-
if (error.headers.status) {
63-
status = parseInt(error.headers.status, 10);
64-
// only re-throw for client errors (4xx), for server errors (5xx) we want to fall back to the REST API
65-
if (status >= 400 && status < 500) {
66-
throw error;
67-
}
68-
}
69-
}
70-
console.warn(
71-
`Failed to fetch commits using the GraphQL API, falling back to the REST API. Status Code: ${status}`,
72-
);
73-
return await fetchCommitsRest(opts);
74-
}
75-
}
76-
77-
/**
78-
* Fetches commits between two refs using GitHub's GraphQL API over a single network call.
79-
* Its efficient network-wise but is not as reliable as the REST API (in my findings).
80-
* So keeping both implementations for the time being.
81-
*
82-
* @param {FetchCommitsOptions & {org: string}} param0
83-
* @returns {Promise<FetchedCommitDetails[]>}
84-
*/
85-
export async function fetchCommitsGraphql({ org, token, repo, lastRelease, release }) {
86-
const gql = graphql.defaults({
87-
headers: {
88-
authorization: `token ${token}`,
89-
},
90-
});
91-
/**
92-
* @param {string | null} commitAfter
93-
* @returns {Promise<{repository: {ref: {compare: {commits: CommitConnection}}}}>}
94-
*/
95-
async function fetchCommitsPaginated(commitAfter = null) {
96-
return await gql({
97-
query: `query GetCommitsBetweenRefs($org: String!, $repo: String!, $baseRef: String!, $headRef: String!, $commitCount: Int!, $commitAfter: String) {
98-
repository(owner: $org, name: $repo) {
99-
ref(qualifiedName: $baseRef) {
100-
compare(headRef: $headRef) {
101-
commits(first: $commitCount, after: $commitAfter) {
102-
pageInfo {
103-
hasNextPage
104-
endCursor
105-
}
106-
nodes {
107-
oid
108-
authoredDate
109-
message
110-
author {
111-
user {
112-
login
113-
}
114-
}
115-
associatedPullRequests(first: 1) {
116-
nodes {
117-
number
118-
authorAssociation
119-
author {
120-
login
121-
}
122-
labels(first: 20) {
123-
nodes {
124-
name
125-
}
126-
}
127-
}
128-
}
129-
}
130-
}
131-
}
132-
}
133-
}
134-
}`,
135-
org,
136-
repo,
137-
commitAfter,
138-
baseRef: lastRelease,
139-
headRef: release,
140-
commitCount: 100,
141-
});
142-
}
143-
144-
let hasNextPage = true;
145-
/**
146-
* @type {string | null}
147-
*/
148-
let commitAfter = null;
149-
/**
150-
* @type {import('./github-gql.mjs').CommitNode[]}
151-
*/
152-
let allCommits = [];
153-
// fetch all commits (with pagination)
154-
do {
155-
// eslint-disable-next-line no-await-in-loop
156-
const data = await fetchCommitsPaginated(commitAfter);
157-
const commits = data.repository.ref.compare.commits;
158-
hasNextPage = !!commits.pageInfo.hasNextPage;
159-
commitAfter = hasNextPage ? commits.pageInfo.endCursor : null;
160-
allCommits.push(...commits.nodes);
161-
} while (hasNextPage);
162-
163-
allCommits = allCommits.filter((commit) => commit.associatedPullRequests.nodes.length > 0);
164-
165-
return allCommits.map((commit) => {
166-
const pr = commit.associatedPullRequests.nodes[0];
167-
const labels = pr.labels.nodes.map((label) => label.name);
168-
169-
/**
170-
* @type {FetchedCommitDetails}
171-
*/
172-
return {
173-
sha: commit.oid,
174-
message: commit.message,
175-
labels,
176-
prNumber: pr.number,
177-
author: pr.author.user?.login
178-
? {
179-
login: pr.author.user.login,
180-
association: getAuthorAssociation(pr.authorAssociation),
181-
}
182-
: null,
183-
};
184-
});
49+
return await fetchCommitsRest(opts);
18550
}
18651

18752
/**
@@ -193,7 +58,7 @@ export async function fetchCommitsGraphql({ org, token, repo, lastRelease, relea
19358
*
19459
* @returns {Promise<FetchedCommitDetails[]>}
19560
*/
196-
export async function fetchCommitsRest({ token, repo, lastRelease, release, org }) {
61+
async function fetchCommitsRest({ token, repo, lastRelease, release, org }) {
19762
const octokit = new Octokit({
19863
auth: token,
19964
});
@@ -253,7 +118,7 @@ export async function fetchCommitsRest({ token, repo, lastRelease, release, org
253118

254119
/**
255120
*
256-
* @param {import('./github-gql.mjs').AuthorAssocation} input
121+
* @param {import('./github-types.mjs').AuthorAssocation} input
257122
* @returns {AuthorAssociation}
258123
*/
259124
function getAuthorAssociation(input) {

packages/code-infra/src/utils/github-gql.mts

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export type AuthorAssocation =
2+
| 'MEMBER'
3+
| 'OWNER'
4+
| 'COLLABORATOR'
5+
| 'CONTRIBUTOR'
6+
| 'FIRST_TIME_CONTRIBUTOR'
7+
| 'FIRST_TIMER'
8+
| 'NONE'
9+
| 'MANNEQUIN';

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)