Skip to content

Commit

Permalink
Merge pull request #132 from microsoft/updates
Browse files Browse the repository at this point in the history
Updated corporate metadata views
  • Loading branch information
jeffwilcox committed May 1, 2020
2 parents 719f6ff + a6b0522 commit c8b30f3
Show file tree
Hide file tree
Showing 10 changed files with 410 additions and 329 deletions.
7 changes: 3 additions & 4 deletions business/organization.ts
Expand Up @@ -199,10 +199,9 @@ export class Organization {
}

repository(name: string, optionalEntity?) {
let entity = optionalEntity || {};
// if (!optionalEntity) {
entity.name = name;
// }
const entity = Object.assign({}, optionalEntity || {}, {
name,
});
const repository = new Repository(
this,
entity,
Expand Down
1 change: 0 additions & 1 deletion lib/campaigns.ts
Expand Up @@ -3,7 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

import { ICacheHelper } from './caching';
import CosmosHelper from './cosmosHelper';

export interface ICampaignUserState {
Expand Down
3 changes: 2 additions & 1 deletion middleware/index.ts
Expand Up @@ -17,6 +17,7 @@ import ConnectSession from './session';
import passportConfig from './passport-config';
import Onboard from './onboarding';
import viewServices from '../lib/pugViewServices';
import { IProviders } from '../transitional';

const campaign = require('./campaign');
const officeHyperlinks = require('./officeHyperlinks');
Expand All @@ -25,7 +26,7 @@ const rawBodyParser = require('./rawBodyParser');
module.exports = function initMiddleware(app, express, config, dirname, initializationError) {
config = config || {};
const appDirectory = config && config.typescript && config.typescript.appDirectory ? config.typescript.appDirectory : stripDistFolderName(dirname);
const providers = app.get('providers');
const providers = app.get('providers') as IProviders;
if (initializationError) {
providers.healthCheck.healthy = false;
}
Expand Down
48 changes: 38 additions & 10 deletions routes/api/createRepo.ts
Expand Up @@ -18,10 +18,12 @@ import RenderHtmlMail from '../../lib/emailRender';

import { RepoWorkflowEngine, IRepositoryWorkflowOutput } from '../org/repoWorkflowEngine';
import { IMailProvider } from '../../lib/mailProvider';
import { asNumber } from '../../utils';
import { asNumber, sleep } from '../../utils';
import { IndividualContext } from '../../user';
import NewRepositoryLockdownSystem from '../../features/newRepositoryLockdown';
import { Operations, ICachedEmployeeInformation } from '../../business/operations';
import { Repository } from '../../business/repository';
import { ICorporateLink } from '../../business/corporateLink';

const supportedLicenseExpressions = [
'mit',
Expand Down Expand Up @@ -124,6 +126,7 @@ export async function CreateRepository(req, bodyOverride: unknown, individualCon
if (existingRepoId && !organization.isNewRepositoryLockdownSystemEnabled()) {
throw jsonError(new Error(`Repository ID ${existingRepoId} provided for a repository within the ${organization.name} org that is not configured for existing repository classification`), 422);
}
let repository: Repository = null;
if (!existingRepoId) {
req.app.settings.providers.insights.trackEvent({
name: 'ApiRepoTryCreateForOrg',
Expand All @@ -137,6 +140,9 @@ export async function CreateRepository(req, bodyOverride: unknown, individualCon
let createResult: ICreateRepositoryResult = null;
try {
createResult = await organization.createRepository(parameters.name, parameters);
if (createResult && createResult.repository) {
repository = organization.repositoryFromEntity(createResult.repository);
}
} catch (error) {
req.app.settings.providers.insights.trackEvent({
name: 'ApiRepoCreateForOrgGitHubFailure',
Expand Down Expand Up @@ -240,6 +246,7 @@ export async function CreateRepository(req, bodyOverride: unknown, individualCon
if (response.id != /* loose */ existingRepoId) {
throw new Error(`The ID of the repo ${metadata.repositoryName} does not match ${existingRepoId}`);
}
repository = repositoryByName;
metadata.lockdownState = RepositoryLockdownState.Unlocked;
const repoCreateResponse: ICreateRepositoryApiResult = {
github: response,
Expand Down Expand Up @@ -320,7 +327,16 @@ export async function CreateRepository(req, bodyOverride: unknown, individualCon
req.repoCreateResponse.tasks = output;
if (msProperties.notify && mailProvider) {
try {
await sendEmail(req, mailProvider, req.apiKeyRow, req.correlationId, output, repoWorkflow.request, msProperties, existingRepoId);
let createdUserLink: ICorporateLink = null;
if (providers.linkProvider) {
try {
createdUserLink = await providers.linkProvider.getByThirdPartyId(repoWorkflow.request.createdByThirdPartyId);
} catch (linkError) {
console.log(`Ignored link error during new repo notification: ${linkError}`);
}
}

await sendEmail(req, mailProvider, req.apiKeyRow, req.correlationId, output, repoWorkflow.request, msProperties, existingRepoId, repository, createdUserLink);
} catch (mailSendError) {
console.dir(mailSendError);
}
Expand Down Expand Up @@ -353,8 +369,8 @@ function downgradeBroadAccessTeams(organization, teams) {
}
}

async function sendEmail(req, mailProvider: IMailProvider, apiKeyRow, correlationId: string, repoCreateResults, approvalRequest: RepositoryMetadataEntity, msProperties, existingRepoId: any): Promise<void> {
const { config, operations } = req.app.settings.providers as IProviders;
async function sendEmail(req, mailProvider: IMailProvider, apiKeyRow, correlationId: string, repoCreateResults, approvalRequest: RepositoryMetadataEntity, msProperties, existingRepoId: any, repository: Repository, createdUserLink: ICorporateLink): Promise<void> {
const { config, operations, viewServices } = req.app.settings.providers as IProviders;
const emails = msProperties.notify.split(',');
let targetType = repoCreateResults.fork ? 'Fork' : 'Repo';
if (!repoCreateResults.fork && approvalRequest.transferSource) {
Expand All @@ -374,7 +390,7 @@ async function sendEmail(req, mailProvider: IMailProvider, apiKeyRow, correlatio
if (existingRepoId) {
subject = `${approvalRequest.repositoryName} ${targetType.toLowerCase()} ready`;
}
const emailTemplate = 'repoApprovals/autoCreated';
const emailTemplate = 'newRepository';
const displayHostname = req.hostname;
const approvalScheme = displayHostname === 'localhost' && config.webServer.allowHttp === true ? 'http' : 'https';
const reposSiteBaseUrl = `${approvalScheme}://${displayHostname}/`;
Expand All @@ -389,13 +405,25 @@ async function sendEmail(req, mailProvider: IMailProvider, apiKeyRow, correlatio
if (managerInfo && managerInfo.managerMail) {
mail.cc = managerInfo.managerMail;
}
if (repository) {
try {
await repository.getDetails();
} catch (getDetailsErrorIgnored) {
console.dir(getDetailsErrorIgnored);
}
}
const app = config.brand?.companyName ? `${config.brand.companyName} GitHub` : 'GitHub';
const contentOptions = {
reason: `You are receiving this e-mail because an API request included the e-mail notification address(es) ${msProperties.notify} during the creation of a repo or you are the manager of the person who created the repo.`,
reason: `You are receiving this e-mail because the new repository request included the e-mail notification address(es) ${msProperties.notify}, or, you are the manager of the person who created the repo.`,
headline,
notification: 'information',
app: 'Microsoft GitHub',
app,
correlationId,
approvalRequest,
approvalRequest, // old name
repositoryMetadataEntity: approvalRequest,
repository,
organization: repository ? repository.organization : null,
createdUserLink,
existingRepoId,
results: repoCreateResults,
version: config.logging.version,
Expand All @@ -406,6 +434,8 @@ async function sendEmail(req, mailProvider: IMailProvider, apiKeyRow, correlatio
service: serviceShortName,
serviceOwner: apiKeyRow ? apiKeyRow.owner : undefined,
serviceDescription: apiKeyRow ? apiKeyRow.description : undefined,
viewServices,
isNotBootstrap: true,
};
try {
mail.content = await RenderHtmlMail(req.app.settings.runtimeConfig.typescript.appDirectory, emailTemplate, contentOptions);
Expand All @@ -424,8 +454,6 @@ async function sendEmail(req, mailProvider: IMailProvider, apiKeyRow, correlatio
receipt: null,
eventName: undefined,
};
console.log(mail);
console.dir(mail);
const additionalMail = {...mail};
try {
customData.receipt = await mailProvider.sendMail(mail);
Expand Down
2 changes: 2 additions & 0 deletions transitional.ts
Expand Up @@ -146,6 +146,7 @@ export interface IProviders {
basedir?: string;
eventRecordProvider?: IEventRecordProvider;
campaignStateProvider?: ICampaignHelper;
campaign?: any; // campaign redirection route, poor variable name
corporateContactProvider?: ICorporateContactProvider;
config?: any;
electionProvider?: IElectionEntityProvider;
Expand Down Expand Up @@ -178,6 +179,7 @@ export interface IProviders {
session?: any;
teamCacheProvider?: ITeamCacheProvider;
teamMemberCacheProvider?: ITeamMemberCacheProvider;
viewServices?: any;
witnessRedis?: redis.RedisClient;
witnessRedisHelper?: RedisHelper;
tokenProvider?: ITokenProvider;
Expand Down
22 changes: 17 additions & 5 deletions views/contributions/voting/vote.pug
Expand Up @@ -31,30 +31,42 @@ block content
//- var previousMonthName = moment(start).subtract(1, 'months').format('MMMM')
.container
- var today = new Date()
- var votingEnd = election.votingEnd ? new Date(election.votingEnd) : null

h2= election.title
p= election.description

if votingState == 'Voted' || votingState == 'NotEligible'
if votingState == 'Voted'
h1 Thanks for voting.
else if votingState == 'NotEligible'
h2 You're not eligible to vote this time.

p
if vote
- var votedDate = new Date(vote.voted)
- var votedMoment = moment(votedDate)
= 'Thank you for your vote. You cast your vote ' + votedMoment.fromNow() + '. '

= 'So far, ' + totalVotes + ' votes have been cast. '

if votingEnd && today > votingEnd
= totalVotes + ' votes were cast. '
else
= 'So far, ' + totalVotes + ' votes have been cast. '
if election && election.votingEnd
- var ve = new Date(election.votingEnd)
- var vem = moment(ve)
= 'Voting ends ' + vem.fromNow() + '.'
if votingEnd && today > votingEnd
= 'Voting ended ' + vem.fromNow() + '.'
else
= 'Voting ends ' + vem.fromNow() + '.'

if results
hr
h4 CURRENT RESULTS

if votingEnd && today > votingEnd
h4 FINAL RESULTS
else
h4 CURRENT RESULTS
- var count = 0
each result in results
- var nomination = result.nomination
Expand Down
6 changes: 4 additions & 2 deletions views/email/footer.pug
Expand Up @@ -42,11 +42,13 @@
p.footer
| #{companyName} Open Source Programs Office
br
a(href='https://aka.ms/opensource') aka.ms/opensource
| &nbsp;&bull;&nbsp;
a(href='https://stackoverflow.microsoft.com/tags/opensource') StackOverflow@Microsoft
| &nbsp;&bull;&nbsp;
a(href='https://opensource.microsoft.com') Web
a(href='https://opensource.microsoft.com') https://opensource.microsoft.com
| &nbsp;&bull;&nbsp;
a(href='mailto:opensource@microsoft.com') Email
a(href='mailto:opensource@microsoft.com') opensource@microsoft.com

td(width='120', valign='middle')
img(align='right', valign='middle', src='https://ospomail.azureedge.net/microsoft.png', width='108', height='23', alt='Microsoft')
Expand Down
Expand Up @@ -3,7 +3,7 @@
//- Licensed under the MIT license. See LICENSE file in the project root for full license information.
//-
extends ../email
extends email

block content
h1 #{approvalRequest.organizationName}/#{approvalRequest.repositoryName}
Expand Down Expand Up @@ -37,11 +37,11 @@ block content
take your repo public with a single click here:
p: a(href=liveReposSiteUrl + approvalRequest.org + '/repos/' + approvalRequest.repoName)= liveReposSiteUrl + approvalRequest.org + '/repos/' + approvalRequest.repoName

if approvalRequest.initialLicense
//-if approvalRequest.initialLicense
h3 License
p= approvalRequest.initialLicense
if approvalRequest.releaseReviewType
//-if approvalRequest.releaseReviewType
h3 Open Source Approval
p
| Release Type: #{approvalRequest.releaseReviewType}
Expand All @@ -51,6 +51,7 @@ block content
if approvalRequest.releaseReviewJustification
br
| Business Justification: #{approvalRequest.releaseReviewJustification}
if service || serviceOwner || serviceDescription
h3 Service information
p This repo was created by a service:
Expand Down Expand Up @@ -78,4 +79,10 @@ block content
if managerInfo && managerInfo.managerMail
h3 Additional notifications
p For visibility, the manager #{managerInfo.managerDisplayName ? managerInfo.managerDisplayName : managerInfo.managerMail} was also notified of this new GitHub repo for open source.


if repository && repositoryMetadataEntity && repositoryMetadataEntity.repositoryName && repositoryMetadataEntity.organizationName
h3 Associated corporate metadata
if repository
p This information is available at #[a(href=repository.absoluteBaseUrl)=repository.absoluteBaseUrl]
include ../includes/corporateRepoMetadata

0 comments on commit c8b30f3

Please sign in to comment.