-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Previews in PR Conversation #224
Open
IstoraMandiri
wants to merge
14
commits into
twitter-together:main
Choose a base branch
from
IstoraMandiri:fix-previews
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0a34264
fix: PR previews for new frontmatter types
IstoraMandiri ab9c94a
Add required `name` to workflow docs
IstoraMandiri 217f4cb
fix: validate preview tweet reference #221
IstoraMandiri 41f43f7
Linting
IstoraMandiri f09f4e8
Merge fix previews, resolve conflicts
IstoraMandiri 1b4b829
Render image in media previews
IstoraMandiri eefe1b1
Fix nested media previews
IstoraMandiri 4216a99
Updating comment in PR thread, better previews
IstoraMandiri 4cc21bb
Skip redudant check run if using comments
IstoraMandiri d148b5d
Refactor, update comment footer
IstoraMandiri 80d559d
Update docs for PR comments
IstoraMandiri 76d3af7
Typo fix
IstoraMandiri ac64942
Do not report "null" for media without alt text
IstoraMandiri 8ba8ea1
Prettier formatting
IstoraMandiri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = parseTweetId; | ||
|
||
const TWEET_REGEX = /^https:\/\/twitter\.com\/[^/]+\/status\/(\d+)$/; | ||
|
||
// TODO allow differently formatted URLs and tweet ids ? | ||
// https://github.com/twitter-together/action/issues/221 | ||
|
||
// TODO: Should we check if the referenced tweet actually exists? | ||
|
||
function parseTweetId(tweetRef) { | ||
const match = tweetRef.match(TWEET_REGEX); | ||
if (!match) { | ||
throw new Error(`Invalid tweet reference: ${tweetRef}`); | ||
} | ||
return match; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
test/pull-request-has-tweet-with-front-matter-media/event.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"action": "opened", | ||
"pull_request": { | ||
"number": 123, | ||
"base": { | ||
"ref": "main" | ||
}, | ||
"head": { | ||
"sha": "0000000000000000000000000000000000000002", | ||
"repo": { | ||
"fork": false | ||
} | ||
} | ||
}, | ||
"repository": { | ||
"default_branch": "main", | ||
"name": "action", | ||
"owner": { | ||
"login": "twitter-together" | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions
102
test/pull-request-has-tweet-with-front-matter-media/test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* This test checks the happy path of pull request adding a new *.tweet file | ||
*/ | ||
|
||
const nock = require("nock"); | ||
const tap = require("tap"); | ||
const path = require("path"); | ||
|
||
// SETUP | ||
process.env.GITHUB_EVENT_NAME = "pull_request"; | ||
process.env.GITHUB_TOKEN = "secret123"; | ||
process.env.GITHUB_EVENT_PATH = require.resolve("./event.json"); | ||
|
||
// set other env variables so action-toolkit is happy | ||
process.env.GITHUB_REF = ""; | ||
process.env.GITHUB_WORKSPACE = path.dirname(process.env.GITHUB_EVENT_PATH); | ||
process.env.GITHUB_WORKFLOW = ""; | ||
process.env.GITHUB_ACTION = "twitter-together"; | ||
process.env.GITHUB_ACTOR = ""; | ||
process.env.GITHUB_REPOSITORY = ""; | ||
process.env.GITHUB_SHA = ""; | ||
|
||
// MOCK | ||
nock("https://api.github.com", { | ||
reqheaders: { | ||
authorization: "token secret123", | ||
}, | ||
}) | ||
// get changed files | ||
.get("/repos/twitter-together/action/pulls/123/files") | ||
.reply(200, [ | ||
{ | ||
status: "added", | ||
filename: "tweets/hello-world.tweet", | ||
}, | ||
]); | ||
|
||
// get pull request diff | ||
nock("https://api.github.com", { | ||
reqheaders: { | ||
accept: "application/vnd.github.diff", | ||
authorization: "token secret123", | ||
}, | ||
}) | ||
.get("/repos/twitter-together/action/pulls/123") | ||
.reply( | ||
200, | ||
`diff --git a/media/cat.jpg b/media/cat.jpg | ||
new file mode 100644 | ||
index 0000000..a10d505 | ||
Binary files /dev/null and b/media/cat.jpg differ | ||
diff --git a/media/dog.jpg b/media/dog.jpg | ||
new file mode 100644 | ||
index 0000000..7a25bfb | ||
Binary files /dev/null and b/media/dog.jpg differ | ||
diff --git a/tweets/media.tweet b/tweets/media.tweet | ||
new file mode 100644 | ||
index 0000000..1715c04 | ||
--- /dev/null | ||
+++ b/tweets/media.tweet | ||
@@ -0,0 +1,9 @@ | ||
+--- | ||
+media: | ||
+ - file: cat.jpg | ||
+ alt: A cat | ||
+ - file: dog.jpg | ||
+ alt: A dog | ||
+--- | ||
+ | ||
+Here are some cute animals!` | ||
); | ||
|
||
// create check run | ||
nock("https://api.github.com") | ||
// get changed files | ||
.post("/repos/twitter-together/action/check-runs", (body) => { | ||
tap.equal(body.name, "preview"); | ||
tap.equal(body.head_sha, "0000000000000000000000000000000000000002"); | ||
tap.equal(body.status, "completed"); | ||
tap.equal(body.conclusion, "success"); | ||
tap.same(body.output, { | ||
title: "1 tweet(s)", | ||
summary: `### ✅ Valid | ||
|
||
Uploading media: | ||
|
||
- cat.jpg [A cat] | ||
- dog.jpg [A dog] | ||
|
||
> Here are some cute animals!`, | ||
}); | ||
|
||
return true; | ||
}) | ||
.reply(201); | ||
|
||
process.on("exit", (code) => { | ||
tap.equal(code, 0); | ||
tap.same(nock.pendingMocks(), []); | ||
}); | ||
|
||
require("../../lib"); |
22 changes: 22 additions & 0 deletions
22
test/pull-request-has-tweet-with-front-matter-poll-5-options/event.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"action": "opened", | ||
"pull_request": { | ||
"number": 123, | ||
"base": { | ||
"ref": "main" | ||
}, | ||
"head": { | ||
"sha": "0000000000000000000000000000000000000002", | ||
"repo": { | ||
"fork": false | ||
} | ||
} | ||
}, | ||
"repository": { | ||
"default_branch": "main", | ||
"name": "action", | ||
"owner": { | ||
"login": "twitter-together" | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a great idea, can you file a follow up issue?