Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
31e677f
Made a test PR.
Apr 26, 2018
c282011
Update bot names.
Apr 26, 2018
41daa0d
Added an update progress indicator.
Apr 26, 2018
10fd926
Save progress.
Apr 27, 2018
924aa85
Save progress.
Apr 30, 2018
7fe14ca
Saved progress.
May 1, 2018
940d126
Updated gitignore.
May 4, 2018
bc85f19
Split out thread/queue handling.
May 4, 2018
02d69ca
Merge from Apple-Shared-Source.
May 4, 2018
6095027
Merge from Apple-Shared-Source.
May 4, 2018
a49cbed
Merge from Apple-Shared-Source.
May 4, 2018
6ff4a41
Save progress.
May 9, 2018
2a2d24a
Save progress.
May 10, 2018
273f0a0
Save progress.
May 10, 2018
582bb1b
Save status.
May 10, 2018
4cbdade
Save progress.
May 11, 2018
c51dd0f
Added preferences.
May 11, 2018
cfdd2bd
Clean up code.
May 11, 2018
0c4c48f
Updated names.
May 11, 2018
c11dc32
Merge from Apple-Shared-Source.
May 12, 2018
2cdb7c6
.
May 12, 2018
3b9db75
Added the status panel.
Jul 30, 2018
b44e75c
Updated status panel.
Aug 2, 2018
2f51574
Better status panel.
Aug 26, 2018
cd6b5e6
.
Aug 28, 2018
4a06700
Added settings.
Sep 7, 2018
6256c76
Clean up code and fix settings.
Sep 8, 2018
425afea
Clean up code.
Sep 12, 2018
fae226b
Code reorg and UI improvements.
Sep 14, 2018
c6cf4ae
Add servers.
Sep 15, 2018
425650a
Changed status panel to popover. Worked on adding a server in prefere…
Sep 18, 2018
d19e4be
Add servers to preferences.
Sep 18, 2018
c27b528
Updated settings.
Sep 20, 2018
578c62b
Updated UI, hooked more parts up. Prefs working.
Sep 22, 2018
a2a482a
Fixed add server.
Sep 24, 2018
59e88eb
Updated server lookup.
Sep 28, 2018
93621df
Refactor APFormattedString.
Sep 29, 2018
735ab82
Updated formatted string. Updated status and pop over.
Oct 1, 2018
79c3d85
Updated status view controller for better repo monitor UI.
Oct 2, 2018
d16201b
Save template bot and update sort.
Oct 3, 2018
6bc1302
Update PR.
Oct 3, 2018
f8cefe5
Save work.
Oct 6, 2018
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
.DS_Store
.LSOverride

# merge-repo commit/discard file
merge-repo-commit

## Build generated
[Bb]uild/
DerivedData/
Expand Down
Binary file added Art/AppIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Art/Icon.sketch
Binary file not shown.
Binary file added Art/Images.sketch
Binary file not shown.
28 changes: 28 additions & 0 deletions Art/makeicons
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -euo pipefail

imagefile="$1"
imagefile="$(resolvepath "$imagefile")"
pathname="$(dirname "$imagefile")"/Build
name="$(basename "$imagefile")"
name="${name%.*}"

mkdir -p "$pathname"

function resizeImage() {
local size=$1
sips --resampleHeightWidth $size $size \
--setProperty dpiHeight 72.0 \
--setProperty dpiWidth 72.0 \
--setProperty format png \
"${imagefile}" \
--out "${pathname}"/"${name}""@"${size}.png &>/dev/null
}

resizeImage 16
resizeImage 32
resizeImage 64
resizeImage 128
resizeImage 256
resizeImage 512
resizeImage 1024
179 changes: 2 additions & 177 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,180 +4,5 @@ A macOS app that creates new Xcode bots when a new PR is created on an observed

There are projects for a full Mac app and another for a command line utility.

* [To Do](#to-do)
* [Overview](#overview)
* [Command Line and Help](#command-line-and-help)
* [Program Flow](#program-flow)
* [References](#references)
* [Xcode Bot Documentation](#xcode-bot-documentation)
* [GitHub Documentation](#github-documentation)
* [Note Pad](#note-pad)

## To Do
```
* [x] Parse command line options.
* [x] Xcode server status.
* [x] Create Xcode bots from new PRs.
* [x] Start rough version of the Mac app.
* [ ] Update integration status in GitHub.
* [ ] Clean up command line logging and messages.
* [ ] Polish Documentation.
```

## Overview

This command line tool creates a new Xcode test bot when a new PR on a GitHub repo is created.

When a new PR is created, this app creates a new Xcode test bot on an Xcode server based on an existing template bot and schedules it to run. The bot will report the test status back on GitHub.

## Command Line and Help
[Standard command line parsers.](https://stackoverflow.com/questions/9642732/parsing-command-line-arguments)

```
xcode-github - Creates an Xcode test bots for new GitHub PRs.

usage: xcode-github [-dhsVv] -g <github-auth-token>
-t <bot-template> -x <xcode-server-domain-name>


-d, --dryrun
Dry run. Print what would be done.

-g, --github <github-auth-token>
A GitHub auth token that allows checking the status of a repo
and change a PR's status.

-h, --help
Print this help information.

-s, --status
Only print the status of the xcode server bots and quit.

-t --template <bot-template>
An existing bot on the xcode server that is used as a template
for the new GitHub PR bots.

-V, --version
Show version and exit.

-v, --verbose
Verbose. Extra 'v' increases the verbosity.

-x, --xcodeserver <xcode-server-domain-name>
The network name of the xcode server.
```

## Program Flow

```
GitHub "New PR" Event -> xcode-github clones a new Xcode bot based on an existing bot
Changes GitHub status to pending
Xcode runs the test bot
Changes GitHub status to success or fail.
GitHub "Close PR" Event -> xcode-github deletes Xcode Bot
```

`xcode-github` Flow

1. Get the latest bots from Xcode server.
* Make sure the template bot exists.
1. Git the latest PRs for the repo.
1. Loop through PRs:
* If PR doesn't have a bot, create bot based on the template bot.
1. Loop through bots:
* If a bot is one of 'our' bots, and the PR is not open, delete it.

### Xcode Bot Flow
* Test start: Change GitHub PR status to 'Pending'.
* Run tests.
* Test end: Change GitHub PR status to 'Passed' or 'Failed'.

## References

### Xcode Bot Documentation

[Xcode Bot Documentation](https://developer.apple.com/library/content/documentation/Xcode/Conceptual/XcodeServerAPIReference/Bots.html)

#### List All Bots

GET https://server.mycompany.com:20343/api/bots
curl -k https://esmith.local:20343/api/bots

#### Copy Bot from Template

POST https://server.mycompany.com:20343/api/bots/{bot-id}/duplicate
Headers
Content-Type: application/json
Body
The properties to be set after the bot has been duplicated.

```
curl --insecure --request POST \
--header 'Content-Type: application/json' \
--data '{ "name": "My new bot" }' \
https://esmith.local:20343/api/bots/1a023fbac7f749ede507153bb43e75e3
```


#### Delete Bot
DELETE https://server.mycompany.com:20343/api/bots/{bot-id}
curl --insecure --request DELETE https://esmith.local:20343/api/bots/1a023fbac7f749ede507153bb43e75e3`

#### Get Bot Status
GET https://esmith.local:20343/api/bots/{bot-id}/integrations?last=1
curl -k https://esmith.local:20343/api/bots/1a023fbac7f749ede507153bb43d6878/integrations?last=1

#### Start Integration
POST https://esmith.local:20343/api/bots/{bot-id}/integrations
```
{
shouldClean: true
}
```

### GitHub Documentation
* [GitHub API Documentation](https://developer.github.com/v3/)
* [GitHub CI Server Documentation](https://developer.github.com/v3/guides/building-a-ci-server/)

#### Get Pull Requests for a Repo
```
curl \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Authorization: token 13e499f7d9ba4fca42e4715558d1e5bc30a6a4e9' \
https://api.github.com/repos/BranchMetrics/ios-branch-deep-linking/pulls?state=open\&sort=created\&direction=desc \
| prettyjson
```

#### Update Pull Request Status
[Pull Request Status Documentation](https://developer.github.com/v3/repos/statuses/)

POST /repos/:owner/:repo/statuses/:sha
```
{
"state": "success",
"target_url": "https://example.com/build/status",
"description": "The build succeeded!",
"context": "continuous-integration/jenkins"
}
```

#### List Pull Request Status
GET /repos/:owner/:repo/commits/:ref/statuses
```
curl \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Authorization: token 13e499f7d9ba4fca42e4715558d1e5bc30a6a4e9' \
https://api.github.com/repos/BranchMetrics/ios-branch-deep-linking/commits/push-notifications/statuses
```

## Note Pad
```
curl -k https://esmith.local:20343/api/bots | prettyjson
curl -k https://esmith.local:20343/api/bots/1a023fbac7f749ede507153bb43d6878/integrations?last=1 | prettyjson

Integration Link in Status Message:
https://stlt.herokuapp.com/v1/xcs_deeplink/qabot.stage.branch.io/f58eba9902ec5f7f8dd96c518f88b617/fe902cbba44b59ff95b81a640158bc6f
=>
xcbot://qabot.stage.branch.io/botID/f58eba9902ec5f7f8dd96c518f88b617/integrationID/fe902cbba44b59ff95b81a640158bc6f
```

`xcode-github` is the command line tool.
`xcode-github-app` is the Mac app project.
40 changes: 40 additions & 0 deletions Vendor/Branch/APFormattedString.Test.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
@file APPFormattedString.Test.m
@package xcode-github-app
@brief Tests for APPFormattedString.

@author Edward Smith
@date April 2018
@copyright Copyright © 2018 Branch. All rights reserved.
*/

#import "BNCTestCase.h"
#import "APFormattedString.h"

@interface APFormattedStringTest : BNCTestCase
@end

@implementation APFormattedStringTest

- (APFormattedString*) createTestString {
APFormattedString *string =
[[[APFormattedString
plainText:@"Ten: %ld.", (long) 10]
boldText:@" Bold text."]
plainText:@" Normal text."];
return string;
}

- (void) testText {
APFormattedString *string = [self createTestString];
NSString* result = [string renderText];
XCTAssertEqualObjects(result, @"Ten: 10. Bold text. Normal text.");
}

- (void) testMarkDown {
APFormattedString *string = [self createTestString];
NSString* result = [string renderMarkDown];
XCTAssertEqualObjects(result, @"Ten: 10.** Bold text.** Normal text.");
}

@end
41 changes: 41 additions & 0 deletions Vendor/Branch/APFormattedString.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
@file APFormattedString.h
@package xcode-github
@brief A generalized formatted string that can render multiple formats.

@author Edward Smith
@date April 2018
@copyright Copyright © 2018 Branch. All rights reserved.
*/

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface APFormattedString : NSObject

+ (instancetype) plainText:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
+ (instancetype) boldText:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
+ (instancetype) italicText:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
+ (instancetype) line;

- (instancetype) plainText:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
- (instancetype) boldText:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
- (instancetype) italicText:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
- (instancetype) line;

- (instancetype) append:(APFormattedString*)string;

- (NSString*) renderText;
- (NSString*) renderMarkDown;

#if TARGET_OS_IOS
- (NSAttributedString*) renderAttributedStringWithFont:(UIFont*)font;
#elif TARGET_OS_OSX
- (NSAttributedString*) renderAttributedStringWithFont:(NSFont*)font;
#endif

@end

NS_ASSUME_NONNULL_END
Loading