Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

added basic setup page for the app #123

Closed
wants to merge 5 commits into from
Closed
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
39 changes: 38 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
const RallyValidate = require('./lib/RallyValidate')
const express = require('express')
const path = require('path')

/**
* Resolve a template path by basename in the `views` directory
*
* Probot already sets a template path so we need a way to
* resolve where our custom templates are so we can pass a
* full path to res.render in our routes.
*
* Example:
* getTemplatePath('index') will resolve to <approot>/views/index
*
* The .hbs extension is implied
*
* @param {string} name
* @returns {string} calculated filepath to template
*/
function getTemplatePath(name) {
return path.join(__dirname, 'views', name)
}

/**
* This is the main entrypoint to your Probot app
Expand All @@ -13,4 +34,20 @@ module.exports = app => {

app.on(['check_run.rerequested', 'check_suite.rerequested'], async context => handler.rerunCheck(context))
app.on('pull_request.closed', async context => handler.handlePullRequestClosed(context))
}

const router = app.route('/setup')

/*
* Serve everything under <approot>/public as static content
* http://127.0.0.1:3000/rally/css/main.css will serve the file
* from <approot>/public/css/main.css
*/
router.use(express.static(path.join(__dirname, 'public')))

router.get('/', (_, res) => {
const setup = require('./lib/setup.js')
console.log(setup)
const index = getTemplatePath('setup')
res.render(index, { title: 'Rally + GitHub: Setup', config: setup.config })
});
};
23 changes: 23 additions & 0 deletions lib/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const fs = require("fs");
const os = require("os");
const contents = fs.readFileSync(".env.example", "utf8");

function deserialize(env) {
return env
.split(/\r?\n/)
.filter((line) => line.length && !line.startsWith("#"))
.map((line) => {
const [key, value] = line.split("=");
return { key, value };
});
}

function serialize(env) {
env.map(({ key, value }) => `${key}=${value}`).join(os.EOL);
}

const config = deserialize(contents);

exports.config = config;

console.log(config);
5 changes: 5 additions & 0 deletions public/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
html,
body {
margin: 0;
padding: 0;
}
3 changes: 3 additions & 0 deletions public/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
document.addEventListener("DOMContentLoaded", function () {
// ready to manipulate the DOM
});
41 changes: 41 additions & 0 deletions views/setup.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en" class="height-full">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{{title}} | built with Probot</title>
<link rel="icon" href="/probot/static/probot-head.png">
<link rel="stylesheet" href="/probot/static/primer.css">
</head>
<body class="height-full bg-gray-light">
<div class="d-flex flex-column flex-justify-center flex-items-center text-center height-full">
<img src="/probot/static/robot.svg" alt="Probot Logo" width="100" class="mb-6">
<div class="box-shadow rounded-2 border p-6 bg-white">
<h1>
{{title}}
</h1>

<form action="#">
{{#each config}}
<label for="{{key}}">{{key}}:</label>
<input type="text" class="form-control input-sm" id="{{key}}" name="{{key}}" default="{{value}}"><br>
{{/each}}
<div class="form-actions">
<br>
<button type="submit" class="btn btn-primary">Save changes</button>
<button type="button" class="btn">Cancel</button>
</div>
</form>
</div>

<div class="mt-4">
<h4 class="alt-h4 text-gray-light">Need help?</h4>
<div class="d-flex flex-justify-center mt-2">
<a href="https://github.com/github/rally" class="btn btn-outline mr-2">Documentation</a>
<a href="https://probot-slackin.herokuapp.com/" class="btn btn-outline">Chat on Slack</a>
</div>
</div>
</div>
</body>
</html>