Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/actions/branch/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: 'Branch from fork'
description: 'creates a branch based off PR from fork'
runs:
using: 'node16'
main: 'index.js'
54 changes: 54 additions & 0 deletions .github/actions/branch/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const core = require('@actions/core');
const github = require('@actions/github');

const octokit = new github.GitHub(process.env.GITHUB_TOKEN);
run();
// Creates a branch off a fork PR
async function run() {
const context = github.context;
try {
// Get info of the fork PR
const prNumber = context.issue.number;
const {data} = await octokit.pulls.get({
...context.repo,
pull_number: prNumber
});
const branch = `${data.user.login}-${data.head.ref}`;
const ref = `refs/heads/${branch}`;
const sha = data.merge_commit_sha;

let res;
// Look up if branch for fork PR exists in base repo
try {
res = await octokit.repos.getBranch({
...context.repo,
branch
});
} catch (error) {
if (!(error.name === 'HttpError' && error.status === 404)) {
throw error;
} else {
// If branch doesn't exist for the forked PR, create one so we can get a
// build for it and return
await octokit.git.createRef({
...context.repo,
ref,
sha
});
return;
}
}

// If branch already exists update it to match fork PR state.
if (res.status === 200) {
await octokit.git.updateRef({
...context.repo,
sha,
ref: `heads/${branch}`,
force: true
})
}
} catch (error) {
core.setFailed(error.message);
}
}
27 changes: 27 additions & 0 deletions .github/workflows/pr-comment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: PR comment
on: issue_comment

jobs:
pr_commented:
name: PR comment workflow
# TODOs: change the github.repositiory to our actual repo
# - change author association to memeber in actual repo (maybe change to something else entirely)
if: |
github.event.issue.pull_request &&
github.repository == 'LFDanLu/react-spectrum' &&
github.event.comment.author_association == 'OWNER'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: Use Node 16
uses: actions/setup-node@v2
with:
node-version: '16'
- name: install
# TODO: change to yarn when running in RSP
run: yarn install
- name: Comment contains trigger
if: contains(github.event.comment.body, 'test comment')
uses: ./.github/actions/branch
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# [React Spectrum Libraries](https://react-spectrum.adobe.com/)

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences. Dummy commit
commit 2

### React Spectrum

Expand Down