Skip to content

Conversation

@maicol07
Copy link
Member

Closes #7

@maicol07 maicol07 self-assigned this Sep 27, 2025
@maicol07 maicol07 added the infra Related to infrastructure label Sep 27, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a GitHub Actions workflow that automatically creates pull requests in the upstream material-components/material-web repository when PRs are merged into the main-community branch of this fork. The workflow includes validation checks and adds a comment back to the source PR with the upstream PR link.

  • Automated upstream PR creation upon merge to main-community
  • Branch validation to ensure changes are based on main
  • Skip functionality via no-upstream label

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

echo "Checking for existing open PR to $UPSTREAM_REPO with head $REPO_OWNER:$BRANCH"

export GH_TOKEN="$TOKEN"
existing=$(gh pr list -R "$UPSTREAM_REPO" --state open --head "$REPO_OWNER:$BRANCH" --json number --jq '.[0].number')
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jq expression .[0].number will fail with 'null cannot be indexed with number' when the array is empty. Use .[0].number // empty or check array length first to handle cases where no PRs exist.

Copilot uses AI. Check for mistakes.
--base "$BASE_TARGET" \
--head "$REPO_OWNER:$BRANCH"

new_number=$(gh pr list -R "$UPSTREAM_REPO" --state open --head "$REPO_OWNER:$BRANCH" --json number --jq '.[0].number') || true
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jq expression .[0].number will fail with 'null cannot be indexed with number' when the array is empty. Use .[0].number // empty or check array length first to handle cases where no PRs exist.

Suggested change
new_number=$(gh pr list -R "$UPSTREAM_REPO" --state open --head "$REPO_OWNER:$BRANCH" --json number --jq '.[0].number') || true
new_number=$(gh pr list -R "$UPSTREAM_REPO" --state open --head "$REPO_OWNER:$BRANCH" --json number --jq '.[0].number // empty') || true

Copilot uses AI. Check for mistakes.
run: |
labels='${{ toJson(github.event.pull_request.labels) }}'
echo "Labels: $labels"
if echo "$labels" | grep -q '"name":"'"$SKIP_LABEL"'"'; then
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The nested quoting pattern is complex and error-prone. Consider using jq to parse the labels JSON more reliably: if echo '$labels' | jq -e '.[] | select(.name == env.SKIP_LABEL)' >/dev/null 2>&1; then

Suggested change
if echo "$labels" | grep -q '"name":"'"$SKIP_LABEL"'"'; then
if echo "$labels" | jq -e '.[] | select(.name == env.SKIP_LABEL)' >/dev/null 2>&1; then

Copilot uses AI. Check for mistakes.
echo "An upstream PR already exists (#$existing). Exiting."; exit 0; fi

body_content=${PR_BODY:-"(No description provided in the source PR)"}
body_content+="\n\n(Automated upstream mirror of source PR ${REPO_FULL}#${PR_NUMBER} by @${AUTHOR})"
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shell string concatenation with += may not work as expected with newlines. Use body_content=\"${body_content}\n\n(Automated upstream mirror of source PR ${REPO_FULL}#${PR_NUMBER} by @${AUTHOR})\" instead.

Suggested change
body_content+="\n\n(Automated upstream mirror of source PR ${REPO_FULL}#${PR_NUMBER} by @${AUTHOR})"
body_content="${body_content}\n\n(Automated upstream mirror of source PR ${REPO_FULL}#${PR_NUMBER} by @${AUTHOR})"

Copilot uses AI. Check for mistakes.
@bocajthomas
Copy link

The new AI agent is quite useful 👌🏼

name: Mirror merged PR upstream

on:
pull_request:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I do worry about the possibility of just spamming the main repo. I wonder if we shouldn't have a separate branch called upstream or something like that, because let's say if we added a new component through one PR but then realized there is something that needs to be fixed and created and merged a new PR for that, it would create 2 PRs where only one PR would possibly be necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but with another branch we would have one PR with multiple components with one upstream branch

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that as Material Web community grows, it will make review difficult if we continuously update a single large PR

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean for there to be one large PR. I think the main issue is that the PRs are just going to pile up because I don't have any illusions that they would potentially accept new stuff, etc, fixes maybe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. Maybe we can do one branch per component (i.e. feat/components/<component) and then create a PR only for that (and we'll update that branch in the time). The workflow supports the no-upstream label to skip PRs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can do one branch per component (i.e. feat/components/<component) and then create a PR only for that (and we'll update that branch in the time).

Yep I do agree with that I think it is gonna be probably for the best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

infra Related to infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Action to automatically send PR to material web repo

4 participants