Skip to content

Commit

Permalink
refactor: typescript (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
bukinoshita committed Jun 21, 2020
1 parent 4032630 commit da62843
Show file tree
Hide file tree
Showing 21 changed files with 2,319 additions and 995 deletions.
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2.1
orbs:
node: circleci/node@3.0.0
jobs:
build-and-test:
executor:
name: node/default
steps:
- checkout
- run: yarn
- run: yarn test
workflows:
build-and-test:
jobs:
- build-and-test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
dist
88 changes: 88 additions & 0 deletions .kodiak.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# .kodiak.toml
# version is the only required setting in a kodiak config.
# it must be set to 1
version = 1

[merge]
# label to use to enable Kodiak to merge a PR
automerge_label = "ready to merge" # default: "automerge"

# require that the automerge label be set for Kodiak to merge a PR. if you
# disable this Kodiak will immediately attempt to merge every PR you create
require_automerge_label = true

# if this title regex matches, Kodiak will not merge the PR. this is useful
# to prevent merging work in progress PRs
blacklist_title_regex = "^WIP:.*" # default: "^WIP:.*", options: "" (disables regex), a regex string (e.g. ".*DONT\s*MERGE.*")

# if these labels are set Kodiak will not merge the PR
blacklist_labels = [] # default: [], options: list of label names (e.g. ["wip"])

# choose a merge method. If the configured merge method is disabled for a
# repository, Kodiak will report an error in a status message.
method = "squash" # default: "merge", options: "merge", "squash", "rebase"

# once a PR is merged into master, delete the branch
delete_branch_on_merge = true # default: false

# Deprecated: Due to limitations with the GitHub API this feature is
# fundamentally broken and cannot be fixed. Please use the GitHub branch
# protection "required reviewers" setting instead. See this issue/comment
# for more information about why this feature is not fixable: https://github.com/chdsbd/kodiak/issues/153#issuecomment-523057332.
#
# if you request review from a user, don't merge until that user provides a
# review, even if the PR is passing all checks
block_on_reviews_requested = false # default: false

# if there is a merge conflict, make a comment on the PR and remove the
# automerge label. this is disabled when require_automerge_label is enabled
notify_on_conflict = true # default: true

# if there are running status checks on a PR when it's up for merge, don't
# wait for those to finish before updating the branch
optimistic_updates = true # default: true

# use this for status checks that run indefinitely, like deploy jobs or the
# WIP GitHub App
dont_wait_on_status_checks = [] # default: [], options: list of check names (e.g. ["ci/circleci: lint_api"])

# immediately update a PR whenever the target updates. If enabled, Kodiak will
# not be able to efficiently update PRs. Any time the target of a PR updates,
# the PR will update.
#
# If you have multiple PRs against a target like "master", any time a commit
# is added to "master" _all_ of those PRs against "master" will update.
#
# For N PRs against a target you will potentially see N(N-1)/2 updates. If
# this configuration option was disabled you would only see N-1 updates.
#
# If you have continuous integration (CI) run on every commit, enabling this
# configuration option will likely increase your CI costs if you pay per
# minute. If you pay per build host, this will likely increase job queueing.
update_branch_immediately = false # default: false

# if a PR is passing all checks and is able to be merged, merge it without
# placing it in the queue. This will introduce some unfairness where those
# waiting in the queue the longest will not be served first.
prioritize_ready_to_merge = false # default: false


[merge.message]
# by default, github uses the first commit title for the PR of a merge.
# "pull_request_title" uses the PR title.
title = "github_default" # default: "github_default", options: "github_default", "pull_request_title"

# by default, GitHub combines the titles of a PR's commits to create the body
# text of a merge. "pull_request_body" uses the content of the PR to generate
# the body content while "empty" simple gives an empty string.
body = "github_default" # default: "github_default", options: "github_default", "pull_request_body", "empty"

# GitHub adds the PR number to the title of merges created through the UI.
# This setting replicates that feature.
include_pr_number = true # default: true

# markdown is the normal format for GitHub merges
body_type = "markdown" # default: "markdown", options: "plain_text", "markdown", "html"

# useful for stripping HTML comments created by PR templates when the `markdown` `body_type` is used.
strip_html_comments = false # default: false
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

14 changes: 0 additions & 14 deletions index.js

This file was deleted.

8 changes: 8 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "/test/.*",
"testEnvironment": "node",
"moduleFileExtensions": ["ts", "js"]
}
14 changes: 0 additions & 14 deletions lib/api.js

This file was deleted.

18 changes: 0 additions & 18 deletions lib/generate.js

This file was deleted.

3 changes: 0 additions & 3 deletions lib/utils.js

This file was deleted.

2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Bu Kinoshita <bukinoshita@gmail.com> (https://bukinoshita.io)
Copyright (c) 2017 Bu Kinoshita <bukinoshita@gmail.com> (https://bukinoshita.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "gh-polls",
"version": "1.0.3",
"description": "Create a poll with gh-polls",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": "bukinoshita/gh-polls",
"author": "Bu Kinoshita <bukinoshita@gmail.com>",
"license": "MIT",
Expand All @@ -15,24 +16,26 @@
"apex",
"up"
],
"engines": {
"node": ">=10"
},
"files": [
"index.js",
"lib"
"dist"
],
"scripts": {
"test": "xo & ava"
"build": "tsc",
"prepublish": "yarn build",
"test": "jest --config=jest.config.json"
},
"dependencies": {
"axios": "^0.19.0"
"axios": "0.19.2"
},
"devDependencies": {
"ava": "2.4.0",
"eslint-config-prettier": "6.7.0",
"xo": "0.25.3"
},
"xo": {
"extends": [
"prettier"
]
"@sindresorhus/tsconfig": "0.7.0",
"@types/jest": "26.0.0",
"@types/node": "14.0.13",
"jest": "26.0.1",
"ts-jest": "26.1.0",
"typescript": "3.9.5"
}
}
15 changes: 4 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
# gh-polls [![Build Status](https://travis-ci.org/bukinoshita/gh-polls.svg?branch=master)](https://travis-ci.org/bukinoshita/gh-polls)
# gh-polls

> Create a poll with gh-polls

## Install

```bash
$ yarn add gh-polls
```


## Usage

```js
const ghPolls = require('gh-polls')
import { ghPolls } from 'gh-polls'

const options = ["Tobi", "Loki", "Jane"]
const options = ['Tobi', 'Loki', 'Jane']
await ghPolls(options)
```

[![](https://api.gh-polls.com/poll/01BM2ZHFZXYKQV9N3HNFXCBH3N/Tobi)](https://api.gh-polls.com/poll/01BM2ZHFZXYKQV9N3HNFXCBH3N/Tobi/vote)
[![](https://api.gh-polls.com/poll/01BM2ZHFZXYKQV9N3HNFXCBH3N/Loki)](https://api.gh-polls.com/poll/01BM2ZHFZXYKQV9N3HNFXCBH3N/Loki/vote)
[![](https://api.gh-polls.com/poll/01BM2ZHFZXYKQV9N3HNFXCBH3N/Jane)](https://api.gh-polls.com/poll/01BM2ZHFZXYKQV9N3HNFXCBH3N/Jane/vote)


## About

<img src="https://i.imgur.com/M8UCMG8.png" />

`gh-polls (js)` is a node module that returns an `object` with 3 keys `text`, `vote` and `image`. [Tj](https://github.com/tj) created [gh-polls (go)](https://github.com/apex/gh-polls) to be able to use polls on GitHub. With `gh-polls (js)` you can create polls outside GitHub, for example on your own website.


## API

### ghPolls([options])
Expand All @@ -44,16 +40,13 @@ Required

Array of options (string).


## Related


- [apex/gh-polls](https://github.com/apex/gh-polls) – polls for user feedback in GitHub issues
- [apex/up](https://github.com/apex/up) – the serverless webapp tool powering gh-polls
- [Web App](https://app.gh-polls.com/) – GH polls web app
- [GitHub App](https://github.com/apps/polls) – GH polls bot


## License

MIT © [Bu Kinoshita](https://bukinoshita.io)
MIT © [Bu Kinoshita](https://bukinoshita.com)
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"extends": [
"config:base"
],
"extends": ["config:base"],
"assignees": ["bukinoshita"]
}
11 changes: 11 additions & 0 deletions source/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import axios from 'axios'

import { BASE_URL } from './utils'

axios.defaults.baseURL = BASE_URL

export const createPoll = async (options: string[]) => {
const res = await axios.post('/poll', { options })

return res.data.id
}
14 changes: 14 additions & 0 deletions source/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BASE_URL } from './utils'

export const generate = (options: string[], id: string) => {
return options.map((option: string) => {
const name = encodeURIComponent(option)
const url = `${BASE_URL}/poll/${id}/${name}`

return {
text: name,
vote: `${url}/vote`,
image: url
}
})
}
9 changes: 9 additions & 0 deletions source/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createPoll } from './api'
import { generate } from './generate'

export const ghPolls = async (options: string[]) => {
const id = await createPoll(options)
const data = generate(options, id)

return data
}
1 change: 1 addition & 0 deletions source/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const BASE_URL = 'https://api.gh-polls.com'
18 changes: 0 additions & 18 deletions test.js

This file was deleted.

11 changes: 11 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ghPolls } from '../source'

test('gh polls', async () => {
const options = ['a', 'b']
const result = await ghPolls(options)

expect(result.length > 1).toBe(true)
expect(result[0].text).toBe(options[0])
expect(result[0].vote).toBeTruthy()
expect(result[0].image).toBeTruthy()
})
8 changes: 8 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@sindresorhus/tsconfig",
"compilerOptions": {
"outDir": "dist",
"esModuleInterop": true
},
"include": ["source"]
}
Loading

0 comments on commit da62843

Please sign in to comment.