Skip to content

suggest-commit-title-limit - Enable on compare pages - #7689

Merged
fregante merged 6 commits into
refined-github:mainfrom
karlhorky:patch-1
Aug 19, 2024
Merged

fregante merged 6 commits into
refined-github:mainfrom
karlhorky:patch-1

Conversation

@karlhorky

@karlhorky karlhorky commented Aug 15, 2024 •

Copy link
Copy Markdown
Contributor

@fregante

Copy link
Copy Markdown
Member

Nope, not enough:

Screenshot

@karlhorky

karlhorky commented Aug 18, 2024 •

Copy link
Copy Markdown
Contributor Author

Interesting, the input field appears to have an attribute id="issue_title" on a PR page eg. #7689

Screenshot 2024-08-18 at 17 21 08

It is id="pull_request_title" on the compare/...?expand=true pages eg. https://github.com/refined-github/refined-github/compare/main...karlhorky:refined-github:test/bun?expand=true

Screenshot 2024-08-18 at 17 21 30

So that leads me to believe that the selector needs to be changed - happy to change this if it doesn't fit the project code style:

Similar selector over here:

onFieldKeydown('#issue_title, #pull_request_title', callback, signal);

@karlhorky
karlhorky marked this pull request as ready for review August 18, 2024 15:45
@karlhorky

Copy link
Copy Markdown
Contributor Author

@fregante anything else I can do in this PR to make it ready?

@fregante
fregante merged commit 5598b75 into refined-github:main Aug 19, 2024
@karlhorky
karlhorky deleted the patch-1 branch August 19, 2024 15:04
@karlhorky

karlhorky commented Aug 22, 2024 •

Copy link
Copy Markdown
Contributor Author

Ah, I think I found a bug in my implementation:

function getConversationNumber(pathname) {
  const [, _owner, _repo, type, prNumber] = pathname.split('/');
  return (type === 'pull' || type === 'issues') && Number(prNumber) ? Number(prNumber) : undefined;
}

getConversationNumber('https://github.com/refined-github/refined-github/compare/main...karlhorky:refined-github:test/bun?expand=true')
// => undefined

export function getConversationNumber(): number | undefined {
const [, _owner, _repo, type, prNumber] = location.pathname.split('/');
return (type === 'pull' || type === 'issues') && Number(prNumber) ? Number(prNumber) : undefined;
}

export function formatPrCommitTitle(title: string): string {
return `${title} (#${getConversationNumber()!})`;
}

This will warn about a PR titles earlier than necessary, because the suffix will be (#undefined) 😮

Fix implementation ideas:

  1. Maybe Refined GitHub has a way to get the "last" or "highest" PR / issue number? (hopefully without requiring a token)
  2. Fetching the issues + PRs, sorted by created-desc and extracting the number from the first HTML element ... 🤔
  3. Does the GitHub GraphQL or REST APIs allow for unauthenticated access to the latest PR or issue number? Update: seems like the REST API can do it:
    curl "https://api.github.com/repos/refined-github/refined-github/issues?sort=created&direction=desc&per_page=1"
    
    [
      {
        ...
        "html_url": "https://github.com/refined-github/refined-github/pull/7726",
        "id": 2480399274,
        "node_id": "PR_kwDOAxXxWc55Gt1w",
        "number": 7726,
        "title": "`tag-changes-link` - Ensure compareLink is added",
    

@fregante

Copy link
Copy Markdown
Member

hopefully without requiring a token

👎 Refined GitHub does not try to avoid token usage because token-less usage is not supported: #7231

This will warn about a PR titles earlier than necessary, because the suffix will be (#undefined)

Good point. We have several options here:

  • count a minimum of 6 characters off (#12)
  • fetch the latest issue/PR via GraphQL

I think being 2 characters off is not a big deal, so even counting 4-digits would be safe for most projects. No HTTP request needed

@karlhorky

karlhorky commented Aug 22, 2024 •

Copy link
Copy Markdown
Contributor Author

Looks like fetching the highest issue / PR is possible like this - not sure if there is code like this already somewhere or whether api.v3 or api.v4 should be used instead:

const response = await fetch(`https://api.github.com/repos/refined-github/refined-github/issues?sort=created&direction=desc&per_page=1`);
const result = await response.json();
console.log(result[0].number); // 7726

@fregante

fregante commented Aug 22, 2024 •

Copy link
Copy Markdown
Member

That should look something like:

const issues = await api.v3('issues?sort=created&direction=desc&per_page=1');
return issues[0].number;

But does issues include PRs as well?

I think that sorting is actually the default though

@karlhorky

karlhorky commented Aug 22, 2024 •

Copy link
Copy Markdown
Contributor Author

But does issues include PRs as well?

Yep #7726 is a PR

Looks like that's the default sorting and direction:

const response = await fetch(`https://api.github.com/repos/refined-github/refined-github/issues?per_page=1`);
const result = await response.json();
console.log(result[0].number); // 7727

I'll open a PR

@karlhorky

Copy link
Copy Markdown
Contributor Author

@karlhorky

Copy link
Copy Markdown
Contributor Author

Thanks for the release of 24.8.26, works well!

@refined-github refined-github locked as resolved and limited conversation to collaborators Aug 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Development

Successfully merging this pull request may close these issues.

2 participants