Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix: handle GitHub URLs in pull request mention id field (#7973)

Jacob Beckerman4e96f117fd03
diff --git a/apps/web/src/lib/service-clients/service-storage/client.ts b/apps/web/src/lib/service-clients/service-storage/client.ts
index 222014e36c..fec0b3f67f 100644
--- a/apps/web/src/lib/service-clients/service-storage/client.ts
+++ b/apps/web/src/lib/service-clients/service-storage/client.ts
@@ -1796,9 +1796,12 @@ export const storageServiceClient = {
}: {
id: string;
}): Promise<Result<ForeignEntity, ResultError<FetchWithTokenErrorCode>[]>> {
- return await dssFetch<ForeignEntity>(`/foreign_entity/${id}`, {
- method: 'GET',
- });
+ return await dssFetch<ForeignEntity>(
+ `/foreign_entity/${encodeURIComponent(id)}`,
+ {
+ method: 'GET',
+ }
+ );
},
/**
diff --git a/crates/mention_utils/src/parse.rs b/crates/mention_utils/src/parse.rs
index a87d5a0fc4..0406e68fb4 100644
--- a/crates/mention_utils/src/parse.rs
+++ b/crates/mention_utils/src/parse.rs
@@ -178,9 +178,14 @@ pub struct ParsedPullRequestMention<'a> {
}
impl ParsedPullRequestMention<'_> {
- /// `owner/repo#123` from the mention's GitHub URL, if it has one.
+ /// `owner/repo#123` from the mention's GitHub URL, if it has one. Agents
+ /// sometimes write that URL in `id`, so it is read from there too.
pub fn github_ref(&self) -> Option<String> {
- let url = self.url.as_deref()?;
+ let url = self
+ .url
+ .as_deref()
+ .filter(|url| !url.is_empty())
+ .unwrap_or(&self.id);
let path = url
.strip_prefix("https://")
.or_else(|| url.strip_prefix("http://"))?;
diff --git a/crates/mention_utils/src/tests.rs b/crates/mention_utils/src/tests.rs
index cea9db2730..6678925a64 100644
--- a/crates/mention_utils/src/tests.rs
+++ b/crates/mention_utils/src/tests.rs
@@ -822,6 +822,13 @@ fn parse_pull_request_mention_by_github_url() {
});
}
+#[test]
+fn pull_request_github_ref_reads_a_url_written_as_the_id() {
+ let input = r#"<m-pr-mention>{"id":"https://github.com/macro-inc/macro/pull/7945","url":null}</m-pr-mention>"#;
+ let rendered = PlainTextFormatter::format_xml_text(ParsedXmlText::parse(input).unwrap()).0;
+ assert_eq!(rendered, "macro-inc/macro#7945");
+}
+
#[test]
fn pull_request_github_ref_ignores_non_pull_urls() {
for url in [
diff --git a/packages/lexical-core/nodes/PullRequestMentionNode.ts b/packages/lexical-core/nodes/PullRequestMentionNode.ts
index c7043615d7..186ca3f85b 100644
--- a/packages/lexical-core/nodes/PullRequestMentionNode.ts
+++ b/packages/lexical-core/nodes/PullRequestMentionNode.ts
@@ -84,10 +84,13 @@ export class PullRequestMentionNode extends DecoratorNode<
key?: NodeKey
) {
super(key);
- this.__id = id;
+ // Agents sometimes put the PR's GitHub URL in `id`. It is not a Macro id,
+ // so treat it as the mention's URL.
+ const idIsUrl = isGithubPullRequestUrl(id);
+ this.__id = idIsUrl ? '' : id;
this.__label = label;
this.__mentionUuid = mentionUuid;
- this.__url = url;
+ this.__url = url || (idIsUrl ? id : undefined);
}
static importJSON(serializedNode: SerializedPullRequestMentionNode) {
diff --git a/packages/lexical-core/tests/pr-mention.test.ts b/packages/lexical-core/tests/pr-mention.test.ts
index 4ad3a7f6a1..e780a931d6 100644
--- a/packages/lexical-core/tests/pr-mention.test.ts
+++ b/packages/lexical-core/tests/pr-mention.test.ts
@@ -39,6 +39,14 @@ describe('PullRequestMentionNode', () => {
);
});
+ it('reads a GitHub URL written as the id as the mention URL', () => {
+ const markdown = `<m-pr-mention>{"id":"${PR_URL}","label":""}</m-pr-mention>`;
+ const state = markdownToSerializedEditorStateWithIds(markdown);
+ expect(state.root.children[0]).toMatchObject({
+ children: [{ type: 'pr-mention', id: '', url: PR_URL }],
+ });
+ });
+
it('rejects a mention with neither an id nor a GitHub PR URL', () => {
const markdown =
'<m-pr-mention>{"url":"https://example.com/pull/1","label":""}</m-pr-mention>';