Skip to content

Commit

Permalink
refactor args
Browse files Browse the repository at this point in the history
  • Loading branch information
allisonport-db committed Dec 3, 2021
1 parent 2af3cf0 commit 188755f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/generate-project-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* GraphQl query to get project and column information
*
* @param {string} url - Issue or Pull request url
* @param {string} is_pr - Whether the event is a Pull Request (false if it's an Issue)
* @param {string} payload - The event payload
* @param {string} project - The project to find
*/
const projectQuery = (url, is_pr, project) =>
const projectQuery = (url, payload, project) =>
`query {
resource( url: "${url}" ) {
... on ${!is_pr ? 'Issue' : 'PullRequest'} {
... on ${!payload.pull_request && !payload.issue.pull_request ? 'Issue' : 'PullRequest'} {
projectCards {
nodes {
id
Expand Down
11 changes: 3 additions & 8 deletions src/get-action-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@ const getActionData = githubContext => {
throw new Error(`Only pull requests, reviews, issues, or comments allowed. Received:\n${eventName}`);
}

const githubData = eventName === 'issues' || eventName === 'issue_comment' ?
payload.issue :
payload.pull_request;
const githubData = payload.issue || payload.pull_request

return {
eventName,
action: payload.action,
nodeId: githubData.node_id,
url: githubData.html_url,
is_pr: !!payload.pull_request || !!payload.issue.pull_request
}
url: githubData.html_url
};
};

module.exports = getActionData;
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const generateMutationQuery = require('./generate-mutation-query');
const action = core.getInput('action') || 'update';

// Get data from the current action
const {eventName, nodeId, url, is_pr} = getActionData(github.context);
const {nodeId, url} = getActionData(github.context);

// Create a method to query GitHub
const octokit = new github.GitHub(token);

// Get the column ID from searching for the project and card Id if it exists
const projectQuery = generateProjectQuery(url, is_pr, project);
const projectQuery = generateProjectQuery(url, github.context.payload, project);

core.debug(projectQuery);

Expand Down

0 comments on commit 188755f

Please sign in to comment.