Skip to content

Commit 5c782cd

Browse files
author
Roshan Jossy
committed
Create API for handling merge request
0 parents  commit 5c782cd

11 files changed

+2286
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules/
2+
/public/build/
3+
4+
.DS_Store

README.md

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
*Psst — looking for a shareable component template? Go here --> [sveltejs/component-template](https://github.com/sveltejs/component-template)*
2+
3+
---
4+
5+
# svelte app
6+
7+
This is a project template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/sveltejs/template.
8+
9+
To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit):
10+
11+
```bash
12+
npx degit sveltejs/template svelte-app
13+
cd svelte-app
14+
```
15+
16+
*Note that you will need to have [Node.js](https://nodejs.org) installed.*
17+
18+
19+
## Get started
20+
21+
Install the dependencies...
22+
23+
```bash
24+
cd svelte-app
25+
npm install
26+
```
27+
28+
...then start [Rollup](https://rollupjs.org):
29+
30+
```bash
31+
npm run dev
32+
```
33+
34+
Navigate to [localhost:5000](http://localhost:5000). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes.
35+
36+
By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the `sirv` commands in package.json to include the option `--host 0.0.0.0`.
37+
38+
39+
## Building and running in production mode
40+
41+
To create an optimised version of the app:
42+
43+
```bash
44+
npm run build
45+
```
46+
47+
You can run the newly built app with `npm run start`. This uses [sirv](https://github.com/lukeed/sirv), which is included in your package.json's `dependencies` so that the app will work when you deploy to platforms like [Heroku](https://heroku.com).
48+
49+
50+
## Single-page app mode
51+
52+
By default, sirv will only respond to requests that match files in `public`. This is to maximise compatibility with static fileservers, allowing you to deploy your app anywhere.
53+
54+
If you're building a single-page app (SPA) with multiple routes, sirv needs to be able to respond to requests for *any* path. You can make it so by editing the `"start"` command in package.json:
55+
56+
```js
57+
"start": "sirv public --single"
58+
```
59+
60+
61+
## Deploying to the web
62+
63+
### With [now](https://zeit.co/now)
64+
65+
Install `now` if you haven't already:
66+
67+
```bash
68+
npm install -g now
69+
```
70+
71+
Then, from within your project folder:
72+
73+
```bash
74+
cd public
75+
now deploy --name my-project
76+
```
77+
78+
As an alternative, use the [Now desktop client](https://zeit.co/download) and simply drag the unzipped project folder to the taskbar icon.
79+
80+
### With [surge](https://surge.sh/)
81+
82+
Install `surge` if you haven't already:
83+
84+
```bash
85+
npm install -g surge
86+
```
87+
88+
Then, from within your project folder:
89+
90+
```bash
91+
npm run build
92+
surge public my-project.surge.sh
93+
```

api/merge.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
module.exports = (req, res) => {
2+
const pullRequest = req.body.pull_request
3+
if (shouldHandlePullRequestChange(req)) {
4+
request(pullRequest.diff_url, (error, response, body) => {
5+
logStatusAndErrors(error, response)
6+
if (isChangeInContributorsFile(body)) {
7+
const options = getPostRequestOptions(pullRequest)
8+
request.put(options, (error, response, body) => {
9+
logStatusAndErrors(error, response)
10+
options.url = `${pullRequest.issue_url}/comments`
11+
if (response.statusCode === 200) {
12+
request.post(options, (error, response, body) => {
13+
logStatusAndErrors(error, response)
14+
})
15+
}
16+
})
17+
}
18+
})
19+
}
20+
res.json({ message: 'Awesome' })
21+
}
22+
23+
24+
25+
const shouldHandlePullRequestChange = req =>
26+
req.body.action === 'opened' && isSingleLineChange(req.body.pull_request)
27+
28+
const isChangeInContributorsFile = diff =>
29+
(diff.match(/Contributors\.md/g) || []).length === 4
30+
31+
const isSingleLineChange = pullRequest =>
32+
(pullRequest.additions === 1 || pullRequest.additions === 2) &&
33+
pullRequest.additions - pullRequest.deletions === 1 &&
34+
pullRequest.changed_files === 1
35+
36+
const getPostRequestOptions = pullRequest => ({
37+
url: `${pullRequest.url}/merge`,
38+
json: {
39+
body: getMergeMessage(pullRequest.user.login)
40+
},
41+
headers: {
42+
Authorization: process.env.GITHUB_SECRET,
43+
'User-Agent': 'request'
44+
}
45+
})
46+
47+
const getMergeMessage = userName => `Hi @${userName}, I'm quite elated about your pull request.
48+
I wanna evolve this project to addresses various problems faced by first-time contributors.
49+
I'd love to learn about your journey in open source community, the problems, pain points you had etc.
50+
could you explain how you felt when you went through the tutorial, made a pull request and learned that i merged it?
51+
52+
We’ve recently added social share to our web app.
53+
Could you please go to https://firstcontributions.github.ios/#social-share
54+
and share your first contribution to open source? Also, check out projects with easy issues while you’re there.`
55+
56+
const logStatusAndErrors = (error, response) => {
57+
console.log('error:', error) // Print the error if one occurred
58+
console.log('statusCode:', response && response.statusCode) // Print the response status code if a response was received
59+
}

package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "svelte-app",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "rollup -c",
6+
"dev": "rollup -c -w",
7+
"start": "sirv public"
8+
},
9+
"devDependencies": {
10+
"@rollup/plugin-commonjs": "^11.0.0",
11+
"@rollup/plugin-node-resolve": "^6.0.0",
12+
"rollup": "^1.20.0",
13+
"rollup-plugin-livereload": "^1.0.0",
14+
"rollup-plugin-svelte": "^5.0.3",
15+
"rollup-plugin-terser": "^5.1.2",
16+
"svelte": "^3.0.0"
17+
},
18+
"dependencies": {
19+
"request": "^2.88.0",
20+
"sirv-cli": "^0.4.4"
21+
}
22+
}

public/favicon.png

3.05 KB
Loading

public/global.css

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
html, body {
2+
position: relative;
3+
width: 100%;
4+
height: 100%;
5+
}
6+
7+
body {
8+
color: #333;
9+
margin: 0;
10+
padding: 8px;
11+
box-sizing: border-box;
12+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
13+
}
14+
15+
a {
16+
color: rgb(0,100,200);
17+
text-decoration: none;
18+
}
19+
20+
a:hover {
21+
text-decoration: underline;
22+
}
23+
24+
a:visited {
25+
color: rgb(0,80,160);
26+
}
27+
28+
label {
29+
display: block;
30+
}
31+
32+
input, button, select, textarea {
33+
font-family: inherit;
34+
font-size: inherit;
35+
padding: 0.4em;
36+
margin: 0 0 0.5em 0;
37+
box-sizing: border-box;
38+
border: 1px solid #ccc;
39+
border-radius: 2px;
40+
}
41+
42+
input:disabled {
43+
color: #ccc;
44+
}
45+
46+
input[type="range"] {
47+
height: 0;
48+
}
49+
50+
button {
51+
color: #333;
52+
background-color: #f4f4f4;
53+
outline: none;
54+
}
55+
56+
button:disabled {
57+
color: #999;
58+
}
59+
60+
button:not(:disabled):active {
61+
background-color: #ddd;
62+
}
63+
64+
button:focus {
65+
border-color: #666;
66+
}

public/index.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset='utf-8'>
5+
<meta name='viewport' content='width=device-width,initial-scale=1'>
6+
7+
<title>Svelte app</title>
8+
9+
<link rel='icon' type='image/png' href='/favicon.png'>
10+
<link rel='stylesheet' href='/global.css'>
11+
<link rel='stylesheet' href='/build/bundle.css'>
12+
13+
<script defer src='/build/bundle.js'></script>
14+
</head>
15+
16+
<body>
17+
</body>
18+
</html>

rollup.config.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import svelte from 'rollup-plugin-svelte';
2+
import resolve from '@rollup/plugin-node-resolve';
3+
import commonjs from '@rollup/plugin-commonjs';
4+
import livereload from 'rollup-plugin-livereload';
5+
import { terser } from 'rollup-plugin-terser';
6+
7+
const production = !process.env.ROLLUP_WATCH;
8+
9+
export default {
10+
input: 'src/main.js',
11+
output: {
12+
sourcemap: true,
13+
format: 'iife',
14+
name: 'app',
15+
file: 'public/build/bundle.js'
16+
},
17+
plugins: [
18+
svelte({
19+
// enable run-time checks when not in production
20+
dev: !production,
21+
// we'll extract any component CSS out into
22+
// a separate file — better for performance
23+
css: css => {
24+
css.write('public/build/bundle.css');
25+
}
26+
}),
27+
28+
// If you have external dependencies installed from
29+
// npm, you'll most likely need these plugins. In
30+
// some cases you'll need additional configuration —
31+
// consult the documentation for details:
32+
// https://github.com/rollup/plugins/tree/master/packages/commonjs
33+
resolve({
34+
browser: true,
35+
dedupe: importee => importee === 'svelte' || importee.startsWith('svelte/')
36+
}),
37+
commonjs(),
38+
39+
// In dev mode, call `npm run start` once
40+
// the bundle has been generated
41+
!production && serve(),
42+
43+
// Watch the `public` directory and refresh the
44+
// browser on changes when not in production
45+
!production && livereload('public'),
46+
47+
// If we're building for production (npm run build
48+
// instead of npm run dev), minify
49+
production && terser()
50+
],
51+
watch: {
52+
clearScreen: false
53+
}
54+
};
55+
56+
function serve() {
57+
let started = false;
58+
59+
return {
60+
writeBundle() {
61+
if (!started) {
62+
started = true;
63+
64+
require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
65+
stdio: ['ignore', 'inherit', 'inherit'],
66+
shell: true
67+
});
68+
}
69+
}
70+
};
71+
}

src/App.svelte

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script>
2+
export let name;
3+
</script>
4+
5+
<main>
6+
<h1>Hello {name}!</h1>
7+
<p>Visit the <a href="https://svelte.dev/tutorial">Svelte tutorial</a> to learn how to build Svelte apps.</p>
8+
</main>
9+
10+
<style>
11+
main {
12+
text-align: center;
13+
padding: 1em;
14+
max-width: 240px;
15+
margin: 0 auto;
16+
}
17+
18+
h1 {
19+
color: #ff3e00;
20+
text-transform: uppercase;
21+
font-size: 4em;
22+
font-weight: 100;
23+
}
24+
25+
@media (min-width: 640px) {
26+
main {
27+
max-width: none;
28+
}
29+
}
30+
</style>

src/main.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import App from './App.svelte';
2+
3+
const app = new App({
4+
target: document.body,
5+
props: {
6+
name: 'world'
7+
}
8+
});
9+
10+
export default app;

0 commit comments

Comments
 (0)